1//
2// cpp/gen/atf_amc_gen.cpp
3// Generated by AMC
4//
5// Copyright (C) 2008-2013 AlgoEngineering LLC
6// Copyright (C) 2013-2019 NYSE | Intercontinental Exchange
7// Copyright (C) 2020-2023 Astra
8// Copyright (C) 2023 AlgoRND
9//
10// This program is free software: you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// This program is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with this program. If not, see <https://www.gnu.org/licenses/>.
22//
23
24
25#include "include/algo.h" // hard-coded include
26#include "include/gen/atf_amc_gen.h"
27#include "include/gen/atf_amc_gen.inl.h"
28#include "include/gen/algo_gen.h"
29#include "include/gen/algo_gen.inl.h"
30#include "include/gen/atfdb_gen.h"
31#include "include/gen/atfdb_gen.inl.h"
32#include "include/gen/lib_exec_gen.h"
33#include "include/gen/lib_exec_gen.inl.h"
34#include "include/gen/command_gen.h"
35#include "include/gen/command_gen.inl.h"
36#include "include/gen/algo_lib_gen.h"
37#include "include/gen/algo_lib_gen.inl.h"
38#include "include/gen/dmmeta_gen.h"
39#include "include/gen/dmmeta_gen.inl.h"
40#include "include/gen/lib_json_gen.h"
41#include "include/gen/lib_json_gen.inl.h"
42#include "include/gen/lib_prot_gen.h"
43#include "include/gen/lib_prot_gen.inl.h"
44//#pragma endinclude
45
46// Instantiate all libraries linked into this executable,
47// in dependency order
48lib_json::FDb lib_json::_db; // dependency found via dev.targdep
49algo_lib::FDb algo_lib::_db; // dependency found via dev.targdep
50lib_exec::FDb lib_exec::_db; // dependency found via dev.targdep
51atf_amc::FDb atf_amc::_db; // dependency found via dev.targdep
52
53atf_amc::cascdel_bh_child_bheap_curs::~cascdel_bh_child_bheap_curs() {
54 algo_lib::malloc_FreeMem(temp_elems, sizeof(void*) * temp_max);
55
56}
57
58atf_amc::_db_bh_typec_curs::~_db_bh_typec_curs() {
59 algo_lib::malloc_FreeMem(temp_elems, sizeof(void*) * temp_max);
60
61}
62
63namespace atf_amc {
64const char *atf_amc_help =
65"atf_amc: Unit tests for amc (see amctest table)\n"
66"Usage: atf_amc [[-amctest:]<regx>] [options]\n"
67" OPTION TYPE DFLT COMMENT\n"
68" -in string \"data\" Input directory or filename, - for stdin\n"
69" [amctest] regx \"%\" SQL regex, selecting test to run\n"
70" -dofork Y Use fork\n"
71" -q Quiet mode\n"
72" -verbose int Verbosity level (0..255); alias -v; cumulative\n"
73" -debug int Debug level (0..255); alias -d; cumulative\n"
74" -help Print help and exit; alias -h\n"
75" -version Print version and exit\n"
76" -signature Show signatures and exit; alias -sig\n"
77;
78
79
80} // namespace atf_amc
81atf_amc::typea_bh_typeb_curs::~typea_bh_typeb_curs() {
82 algo_lib::malloc_FreeMem(temp_elems, sizeof(void*) * temp_max);
83
84}
85
86namespace atf_amc { // gen:ns_gsymbol
87 const char* atfdb_test_gsymbol_char_TestChar("TestChar");
88} // gen:ns_gsymbol
89namespace atf_amc { // gen:ns_gsymbol
90 const atfdb::TestGsymbolPkeyPkey atfdb_test_gsymbol_pkey_TestPkey("TestPkey");
91} // gen:ns_gsymbol
92namespace atf_amc { // gen:ns_gsymbol
93 const algo::strptr atfdb_test_gsymbol_strptr_TestStrptr("TestStrptr");
94} // gen:ns_gsymbol
95namespace atf_amc { // gen:ns_print_proto
96 // func:atf_amc.BitfldType1.bit1.ReadStrptrMaybe
97 static bool bit1_ReadStrptrMaybe(atf_amc::BitfldType1 &parent, algo::strptr in_str) __attribute__((nothrow));
98 // func:atf_amc.BitfldType1.bits5.ReadStrptrMaybe
99 static bool bits5_ReadStrptrMaybe(atf_amc::BitfldType1 &parent, algo::strptr in_str) __attribute__((nothrow));
100 // func:atf_amc.BitfldType2.bit0.ReadStrptrMaybe
101 static bool bit0_ReadStrptrMaybe(atf_amc::BitfldType2 &parent, algo::strptr in_str) __attribute__((nothrow));
102 // func:atf_amc.BitfldType2.bit1.ReadStrptrMaybe
103 static bool bit1_ReadStrptrMaybe(atf_amc::BitfldType2 &parent, algo::strptr in_str) __attribute__((nothrow));
104 // Internal function to shift data left
105 // Shift existing bytes over to the beginning of the buffer
106 // func:atf_amc.Bytebuf.in.Shift
107 static void in_Shift(atf_amc::Bytebuf& bytebuf) __attribute__((nothrow));
108 // Internal function to shift data left
109 // Shift existing bytes over to the beginning of the buffer
110 // func:atf_amc.BytebufDyn.in.Shift
111 static void in_Shift(atf_amc::BytebufDyn& bytebuf_dyn) __attribute__((nothrow));
112 // Extract next character from STR and advance IDX
113 // func:atf_amc.Cstr.val.Nextchar
114 static int val_Nextchar(const atf_amc::Cstr& parent, algo::strptr &str, int &idx) __attribute__((nothrow));
115 // func:atf_amc.DispFilter.strval.ReadStrptrMaybe
116 static bool strval_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) __attribute__((nothrow));
117 // func:atf_amc.DispFilter.strval_regx.ReadStrptrMaybe
118 static bool strval_regx_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) __attribute__((nothrow));
119 // func:atf_amc.DispFilter.strval2.ReadStrptrMaybe
120 static bool strval2_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) __attribute__((nothrow));
121 // func:atf_amc.DispFilter.strval2_regx.ReadStrptrMaybe
122 static bool strval2_regx_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) __attribute__((nothrow));
123 // func:atf_amc.DispFilter.start_dateval.ReadStrptrMaybe
124 static bool start_dateval_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) __attribute__((nothrow));
125 // func:atf_amc.DispFilter.end_dateval.ReadStrptrMaybe
126 static bool end_dateval_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) __attribute__((nothrow));
127 // func:atf_amc.DispFilter.dateval.ReadStrptrMaybe
128 static bool dateval_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) __attribute__((nothrow));
129 // func:atf_amc.DispFilter.start_intval.ReadStrptrMaybe
130 static bool start_intval_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) __attribute__((nothrow));
131 // func:atf_amc.DispFilter.end_intval.ReadStrptrMaybe
132 static bool end_intval_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) __attribute__((nothrow));
133 // func:atf_amc.DispFilter.intval.ReadStrptrMaybe
134 static bool intval_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) __attribute__((nothrow));
135 // Find new location for ROW starting at IDX
136 // NOTE: Rest of heap is rearranged, but pointer to ROW is NOT stored in array.
137 // func:atf_amc.FCascdel.bh_child_bheap.Downheap
138 static int bh_child_bheap_Downheap(atf_amc::FCascdel& cascdel, atf_amc::FCascdel& row, int idx) __attribute__((nothrow));
139 // Find and return index of new location for element ROW in the heap, starting at index IDX.
140 // Move any elements along the way but do not modify ROW.
141 // func:atf_amc.FCascdel.bh_child_bheap.Upheap
142 static int bh_child_bheap_Upheap(atf_amc::FCascdel& cascdel, atf_amc::FCascdel& row, int idx) __attribute__((nothrow));
143 // func:atf_amc.FCascdel.bh_child_bheap.ElemLt
144 static bool bh_child_bheap_ElemLt(atf_amc::FCascdel& cascdel, atf_amc::FCascdel &a, atf_amc::FCascdel &b) __attribute__((nothrow));
145 // func:atf_amc.FCascdel.bh_child_bheap.ElemLtval
146 static bool bh_child_bheap_ElemLtval(atf_amc::FCascdel& cascdel, atf_amc::FCascdel &a, const u32 &b) __attribute__((nothrow));
147 // func:atf_amc.FCascdel.bh_child_bheap_curs.Add
148 static void cascdel_bh_child_bheap_curs_Add(cascdel_bh_child_bheap_curs &curs, atf_amc::FCascdel& row);
149 // Returns the child that has greater height.
150 // func:atf_amc.FCascdel.tr_child_atree.TallerChild
151 static atf_amc::FCascdel* tr_child_atree_TallerChild(atf_amc::FCascdel& node) __attribute__((nothrow));
152 // Disconnects the subtree(branch) from the parent
153 // func:atf_amc.FCascdel.tr_child_atree.Disconnect
154 static void tr_child_atree_Disconnect(atf_amc::FCascdel& node) __attribute__((nothrow));
155 // func:atf_amc.FCascdel.tr_child_atree.ElemLt
156 static bool tr_child_atree_ElemLt(atf_amc::FCascdel& cascdel, atf_amc::FCascdel &a, atf_amc::FCascdel &b) __attribute__((nothrow));
157 // func:atf_amc.FCascdel.tr_child_atree.UpdateDepth
158 static void tr_child_atree_updateDepth(atf_amc::FCascdel& node) __attribute__((nothrow));
159 // rotates the tree in from->to direction
160 // func:atf_amc.FCascdel.tr_child_atree.Turn
161 static void tr_child_atree_Turn(atf_amc::FCascdel& from, atf_amc::FCascdel& to) __attribute__((nothrow));
162 // func:atf_amc.FCascdel.tr_child_atree.Connect
163 static void tr_child_atree_Connect(atf_amc::FCascdel* parent, atf_amc::FCascdel* child, bool left) __attribute__((nothrow));
164 // Find new location for ROW starting at IDX
165 // NOTE: Rest of heap is rearranged, but pointer to ROW is NOT stored in array.
166 // func:atf_amc.FDb.bh_typec.Downheap
167 static int bh_typec_Downheap(atf_amc::FTypeC& row, int idx) __attribute__((nothrow));
168 // Find and return index of new location for element ROW in the heap, starting at index IDX.
169 // Move any elements along the way but do not modify ROW.
170 // func:atf_amc.FDb.bh_typec.Upheap
171 static int bh_typec_Upheap(atf_amc::FTypeC& row, int idx) __attribute__((nothrow));
172 // func:atf_amc.FDb.bh_typec.ElemLt
173 static bool bh_typec_ElemLt(atf_amc::FTypeC &a, atf_amc::FTypeC &b) __attribute__((nothrow));
174 // func:atf_amc.FDb.bh_typec_curs.Add
175 static void _db_bh_typec_curs_Add(_db_bh_typec_curs &curs, atf_amc::FTypeC& row);
176 // func:atf_amc.FDb.types.InputMaybe
177 static bool types_InputMaybe(atf_amc::TypeS &elem) __attribute__((nothrow));
178 // Load statically available data into tables, register tables and database.
179 // func:atf_amc.FDb._db.InitReflection
180 static void InitReflection();
181 // func:atf_amc.FDb.typet.InputMaybe
182 static bool typet_InputMaybe(atf_amc::TypeT &elem) __attribute__((nothrow));
183 // First element of index changed.
184 // func:atf_amc.FDb.cd_in_msg.FirstChanged
185 static void cd_in_msg_FirstChanged() __attribute__((nothrow));
186 // Update cycles count from previous clock capture
187 // func:atf_amc.FDb.cd_in_msg.UpdateCycles
188 static void cd_in_msg_UpdateCycles() __attribute__((nothrow));
189 // func:atf_amc.FDb.cd_in_msg.Call
190 static void cd_in_msg_Call() __attribute__((nothrow));
191 // func:atf_amc.FDb.amctest.LoadStatic
192 static void amctest_LoadStatic() __attribute__((nothrow));
193 // Returns the child that has greater height.
194 // func:atf_amc.FDb.tr_avl.TallerChild
195 static atf_amc::FAvl* tr_avl_TallerChild(atf_amc::FAvl& node) __attribute__((nothrow));
196 // Disconnects the subtree(branch) from the parent
197 // func:atf_amc.FDb.tr_avl.Disconnect
198 static void tr_avl_Disconnect(atf_amc::FAvl& node) __attribute__((nothrow));
199 // func:atf_amc.FDb.tr_avl.ElemLt
200 static bool tr_avl_ElemLt(atf_amc::FAvl &a, atf_amc::FAvl &b) __attribute__((nothrow));
201 // func:atf_amc.FDb.tr_avl.UpdateDepth
202 static void tr_avl_updateDepth(atf_amc::FAvl& node) __attribute__((nothrow));
203 // rotates the tree in from->to direction
204 // func:atf_amc.FDb.tr_avl.Turn
205 static void tr_avl_Turn(atf_amc::FAvl& from, atf_amc::FAvl& to) __attribute__((nothrow));
206 // func:atf_amc.FDb.tr_avl.Connect
207 static void tr_avl_Connect(atf_amc::FAvl* parent, atf_amc::FAvl* child, bool left) __attribute__((nothrow));
208 // func:atf_amc.FDb.listtype.LoadStatic
209 static void listtype_LoadStatic() __attribute__((nothrow));
210 // find trace by row id (used to implement reflection)
211 // func:atf_amc.FDb.trace.RowidFind
212 static algo::ImrowPtr trace_RowidFind(int t) __attribute__((nothrow));
213 // Function return 1
214 // func:atf_amc.FDb.trace.N
215 static i32 trace_N() __attribute__((__warn_unused_result__, nothrow, pure));
216 // Swap values elem_a and elem_b
217 // func:atf_amc.FPerfSortString.sorted1.Swap
218 static void sorted1_Swap(atf_amc::Cstr &elem_a, atf_amc::Cstr &elem_b) __attribute__((nothrow));
219 // Left circular shift of three-tuple
220 // func:atf_amc.FPerfSortString.sorted1.Rotleft
221 static void sorted1_Rotleft(atf_amc::Cstr &elem_a, atf_amc::Cstr &elem_b, atf_amc::Cstr &elem_c) __attribute__((nothrow));
222 // Compare values elem_a and elem_b
223 // The comparison function must be anti-symmetric: if a>b, then !(b>a).
224 // If not, mayhem results.
225 // func:atf_amc.FPerfSortString.sorted1.Lt
226 static bool sorted1_Lt(atf_amc::Cstr &elem_a, atf_amc::Cstr &elem_b) __attribute__((nothrow));
227 // Internal insertion sort
228 // func:atf_amc.FPerfSortString.sorted1.IntInsertionSort
229 static void sorted1_IntInsertionSort(atf_amc::Cstr *elems, int n) __attribute__((nothrow));
230 // Internal heap sort
231 // func:atf_amc.FPerfSortString.sorted1.IntHeapSort
232 static void sorted1_IntHeapSort(atf_amc::Cstr *elems, int n) __attribute__((nothrow));
233 // Quick sort engine
234 // func:atf_amc.FPerfSortString.sorted1.IntQuickSort
235 static void sorted1_IntQuickSort(atf_amc::Cstr *elems, int n, int depth) __attribute__((nothrow));
236 // Find new location for ROW starting at IDX
237 // NOTE: Rest of heap is rearranged, but pointer to ROW is NOT stored in array.
238 // func:atf_amc.FTypeA.bh_typeb.Downheap
239 static int bh_typeb_Downheap(atf_amc::FTypeA& typea, atf_amc::FTypeB& row, int idx) __attribute__((nothrow));
240 // Find and return index of new location for element ROW in the heap, starting at index IDX.
241 // Move any elements along the way but do not modify ROW.
242 // func:atf_amc.FTypeA.bh_typeb.Upheap
243 static int bh_typeb_Upheap(atf_amc::FTypeA& typea, atf_amc::FTypeB& row, int idx) __attribute__((nothrow));
244 // func:atf_amc.FTypeA.bh_typeb.ElemLt
245 static bool bh_typeb_ElemLt(atf_amc::FTypeA& typea, atf_amc::FTypeB &a, atf_amc::FTypeB &b) __attribute__((nothrow));
246 // func:atf_amc.FTypeA.bh_typeb_curs.Add
247 static void typea_bh_typeb_curs_Add(typea_bh_typeb_curs &curs, atf_amc::FTypeB& row);
248 // Swap values elem_a and elem_b
249 // func:atf_amc.FUnitSort.tary.Swap
250 static void tary_Swap(atf_amc::TypeA &elem_a, atf_amc::TypeA &elem_b) __attribute__((nothrow));
251 // Left circular shift of three-tuple
252 // func:atf_amc.FUnitSort.tary.Rotleft
253 static void tary_Rotleft(atf_amc::TypeA &elem_a, atf_amc::TypeA &elem_b, atf_amc::TypeA &elem_c) __attribute__((nothrow));
254 // Compare values elem_a and elem_b
255 // The comparison function must be anti-symmetric: if a>b, then !(b>a).
256 // If not, mayhem results.
257 // func:atf_amc.FUnitSort.tary.Lt
258 static bool tary_Lt(atf_amc::TypeA &elem_a, atf_amc::TypeA &elem_b) __attribute__((nothrow));
259 // Internal insertion sort
260 // func:atf_amc.FUnitSort.tary.IntInsertionSort
261 static void tary_IntInsertionSort(atf_amc::TypeA *elems, int n) __attribute__((nothrow));
262 // Internal heap sort
263 // func:atf_amc.FUnitSort.tary.IntHeapSort
264 static void tary_IntHeapSort(atf_amc::TypeA *elems, int n) __attribute__((nothrow));
265 // Quick sort engine
266 // func:atf_amc.FUnitSort.tary.IntQuickSort
267 static void tary_IntQuickSort(atf_amc::TypeA *elems, int n, int depth) __attribute__((nothrow));
268 // Swap values elem_a and elem_b
269 // func:atf_amc.FUnitSort.c_ptrary.Swap
270 static void c_ptrary_Swap(atf_amc::TypeA* &elem_a, atf_amc::TypeA* &elem_b) __attribute__((nothrow));
271 // Left circular shift of three-tuple
272 // func:atf_amc.FUnitSort.c_ptrary.Rotleft
273 static void c_ptrary_Rotleft(atf_amc::TypeA* &elem_a, atf_amc::TypeA* &elem_b, atf_amc::TypeA* &elem_c) __attribute__((nothrow));
274 // Compare values elem_a and elem_b
275 // The comparison function must be anti-symmetric: if a>b, then !(b>a).
276 // If not, mayhem results.
277 // func:atf_amc.FUnitSort.c_ptrary.Lt
278 static bool c_ptrary_Lt(atf_amc::TypeA &elem_a, atf_amc::TypeA &elem_b) __attribute__((nothrow));
279 // Internal insertion sort
280 // func:atf_amc.FUnitSort.c_ptrary.IntInsertionSort
281 static void c_ptrary_IntInsertionSort(atf_amc::TypeA* *elems, int n) __attribute__((nothrow));
282 // Internal heap sort
283 // func:atf_amc.FUnitSort.c_ptrary.IntHeapSort
284 static void c_ptrary_IntHeapSort(atf_amc::TypeA* *elems, int n) __attribute__((nothrow));
285 // Quick sort engine
286 // func:atf_amc.FUnitSort.c_ptrary.IntQuickSort
287 static void c_ptrary_IntQuickSort(atf_amc::TypeA* *elems, int n, int depth) __attribute__((nothrow));
288 // Swap values elem_a and elem_b
289 // func:atf_amc.FUnitSort.fixary.Swap
290 static void fixary_Swap(atf_amc::TypeA &elem_a, atf_amc::TypeA &elem_b) __attribute__((nothrow));
291 // Left circular shift of three-tuple
292 // func:atf_amc.FUnitSort.fixary.Rotleft
293 static void fixary_Rotleft(atf_amc::TypeA &elem_a, atf_amc::TypeA &elem_b, atf_amc::TypeA &elem_c) __attribute__((nothrow));
294 // Compare values elem_a and elem_b
295 // The comparison function must be anti-symmetric: if a>b, then !(b>a).
296 // If not, mayhem results.
297 // func:atf_amc.FUnitSort.fixary.Lt
298 static bool fixary_Lt(atf_amc::TypeA &elem_a, atf_amc::TypeA &elem_b) __attribute__((nothrow));
299 // Internal insertion sort
300 // func:atf_amc.FUnitSort.fixary.IntInsertionSort
301 static void fixary_IntInsertionSort(atf_amc::TypeA *elems, int n) __attribute__((nothrow));
302 // Internal heap sort
303 // func:atf_amc.FUnitSort.fixary.IntHeapSort
304 static void fixary_IntHeapSort(atf_amc::TypeA *elems, int n) __attribute__((nothrow));
305 // Quick sort engine
306 // func:atf_amc.FUnitSort.fixary.IntQuickSort
307 static void fixary_IntQuickSort(atf_amc::TypeA *elems, int n, int depth) __attribute__((nothrow));
308 // Internal function to scan for a message
309 //
310 // func:atf_amc.Linebuf.in.Scanmsg
311 static void in_Scanmsg(atf_amc::Linebuf& linebuf) __attribute__((nothrow));
312 // Internal function to shift data left
313 // Shift existing bytes over to the beginning of the buffer
314 // func:atf_amc.Linebuf.in.Shift
315 static void in_Shift(atf_amc::Linebuf& linebuf) __attribute__((nothrow));
316 // Internal function to scan for a message
317 //
318 // func:atf_amc.Msgbuf.in.Scanmsg
319 static void in_Scanmsg(atf_amc::Msgbuf& msgbuf) __attribute__((nothrow));
320 // Internal function to shift data left
321 // Shift existing bytes over to the beginning of the buffer
322 // func:atf_amc.Msgbuf.in.Shift
323 static void in_Shift(atf_amc::Msgbuf& msgbuf) __attribute__((nothrow));
324 // Internal function to shift data left
325 // Shift existing bytes over to the beginning of the buffer
326 // func:atf_amc.Msgbuf.out_extra.Shift
327 static void out_extra_Shift(atf_amc::Msgbuf& msgbuf) __attribute__((nothrow));
328 // Internal function to scan for a message
329 //
330 // func:atf_amc.Msgbuf.in_extra.Scanmsg
331 static void in_extra_Scanmsg(atf_amc::Msgbuf& msgbuf) __attribute__((nothrow));
332 // Internal function to shift data left
333 // Shift existing bytes over to the beginning of the buffer
334 // func:atf_amc.Msgbuf.in_extra.Shift
335 static void in_extra_Shift(atf_amc::Msgbuf& msgbuf) __attribute__((nothrow));
336 // func:atf_amc.PmaskMultiple.value1.ReadStrptrMaybe
337 static bool value1_ReadStrptrMaybe(atf_amc::PmaskMultiple &parent, algo::strptr in_str) __attribute__((nothrow));
338 // func:atf_amc.PmaskMultiple.value2.ReadStrptrMaybe
339 static bool value2_ReadStrptrMaybe(atf_amc::PmaskMultiple &parent, algo::strptr in_str) __attribute__((nothrow));
340 // func:atf_amc.PmaskMultiple.value3.ReadStrptrMaybe
341 static bool value3_ReadStrptrMaybe(atf_amc::PmaskMultiple &parent, algo::strptr in_str) __attribute__((nothrow));
342 // func:atf_amc.PmaskMultiple.value4.ReadStrptrMaybe
343 static bool value4_ReadStrptrMaybe(atf_amc::PmaskMultiple &parent, algo::strptr in_str) __attribute__((nothrow));
344 // func:atf_amc.PmaskMultiple.value5.ReadStrptrMaybe
345 static bool value5_ReadStrptrMaybe(atf_amc::PmaskMultiple &parent, algo::strptr in_str) __attribute__((nothrow));
346 // func:atf_amc.PmaskMultiple.value6.ReadStrptrMaybe
347 static bool value6_ReadStrptrMaybe(atf_amc::PmaskMultiple &parent, algo::strptr in_str) __attribute__((nothrow));
348 // func:atf_amc.PmaskMultiple.value7.ReadStrptrMaybe
349 static bool value7_ReadStrptrMaybe(atf_amc::PmaskMultiple &parent, algo::strptr in_str) __attribute__((nothrow));
350 // func:atf_amc.PmaskU128.value.ReadStrptrMaybe
351 static bool value_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
352 // func:atf_amc.PmaskU128.value2.ReadStrptrMaybe
353 static bool value2_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
354 // func:atf_amc.PmaskU128.value3.ReadStrptrMaybe
355 static bool value3_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
356 // func:atf_amc.PmaskU128.value21.ReadStrptrMaybe
357 static bool value21_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
358 // func:atf_amc.PmaskU128.value22.ReadStrptrMaybe
359 static bool value22_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
360 // func:atf_amc.PmaskU128.value23.ReadStrptrMaybe
361 static bool value23_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
362 // func:atf_amc.PmaskU128.value24.ReadStrptrMaybe
363 static bool value24_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
364 // func:atf_amc.PmaskU128.value25.ReadStrptrMaybe
365 static bool value25_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
366 // func:atf_amc.PmaskU128.value26.ReadStrptrMaybe
367 static bool value26_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
368 // func:atf_amc.PmaskU128.value20.ReadStrptrMaybe
369 static bool value20_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
370 // func:atf_amc.PmaskU128.value28.ReadStrptrMaybe
371 static bool value28_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
372 // func:atf_amc.PmaskU128.value29.ReadStrptrMaybe
373 static bool value29_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
374 // func:atf_amc.PmaskU128.value30.ReadStrptrMaybe
375 static bool value30_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
376 // func:atf_amc.PmaskU128.value31.ReadStrptrMaybe
377 static bool value31_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
378 // func:atf_amc.PmaskU128.value32.ReadStrptrMaybe
379 static bool value32_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
380 // func:atf_amc.PmaskU128.value27.ReadStrptrMaybe
381 static bool value27_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
382 // func:atf_amc.PmaskU128.value19.ReadStrptrMaybe
383 static bool value19_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
384 // func:atf_amc.PmaskU128.value18.ReadStrptrMaybe
385 static bool value18_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
386 // func:atf_amc.PmaskU128.value4.ReadStrptrMaybe
387 static bool value4_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
388 // func:atf_amc.PmaskU128.value5.ReadStrptrMaybe
389 static bool value5_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
390 // func:atf_amc.PmaskU128.value6.ReadStrptrMaybe
391 static bool value6_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
392 // func:atf_amc.PmaskU128.value7.ReadStrptrMaybe
393 static bool value7_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
394 // func:atf_amc.PmaskU128.value8.ReadStrptrMaybe
395 static bool value8_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
396 // func:atf_amc.PmaskU128.value9.ReadStrptrMaybe
397 static bool value9_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
398 // func:atf_amc.PmaskU128.value69.ReadStrptrMaybe
399 static bool value69_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
400 // func:atf_amc.PmaskU128.value11.ReadStrptrMaybe
401 static bool value11_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
402 // func:atf_amc.PmaskU128.value12.ReadStrptrMaybe
403 static bool value12_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
404 // func:atf_amc.PmaskU128.value13.ReadStrptrMaybe
405 static bool value13_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
406 // func:atf_amc.PmaskU128.value14.ReadStrptrMaybe
407 static bool value14_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
408 // func:atf_amc.PmaskU128.value15.ReadStrptrMaybe
409 static bool value15_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
410 // func:atf_amc.PmaskU128.value16.ReadStrptrMaybe
411 static bool value16_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
412 // func:atf_amc.PmaskU128.value33.ReadStrptrMaybe
413 static bool value33_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
414 // func:atf_amc.PmaskU128.value10.ReadStrptrMaybe
415 static bool value10_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
416 // func:atf_amc.PmaskU128.value17.ReadStrptrMaybe
417 static bool value17_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
418 // func:atf_amc.PmaskU128.value35.ReadStrptrMaybe
419 static bool value35_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
420 // func:atf_amc.PmaskU128.value55.ReadStrptrMaybe
421 static bool value55_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
422 // func:atf_amc.PmaskU128.value56.ReadStrptrMaybe
423 static bool value56_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
424 // func:atf_amc.PmaskU128.value57.ReadStrptrMaybe
425 static bool value57_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
426 // func:atf_amc.PmaskU128.value58.ReadStrptrMaybe
427 static bool value58_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
428 // func:atf_amc.PmaskU128.value59.ReadStrptrMaybe
429 static bool value59_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
430 // func:atf_amc.PmaskU128.value60.ReadStrptrMaybe
431 static bool value60_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
432 // func:atf_amc.PmaskU128.value54.ReadStrptrMaybe
433 static bool value54_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
434 // func:atf_amc.PmaskU128.value62.ReadStrptrMaybe
435 static bool value62_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
436 // func:atf_amc.PmaskU128.value63.ReadStrptrMaybe
437 static bool value63_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
438 // func:atf_amc.PmaskU128.value64.ReadStrptrMaybe
439 static bool value64_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
440 // func:atf_amc.PmaskU128.value65.ReadStrptrMaybe
441 static bool value65_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
442 // func:atf_amc.PmaskU128.value66.ReadStrptrMaybe
443 static bool value66_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
444 // func:atf_amc.PmaskU128.value67.ReadStrptrMaybe
445 static bool value67_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
446 // func:atf_amc.PmaskU128.value68.ReadStrptrMaybe
447 static bool value68_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
448 // func:atf_amc.PmaskU128.value61.ReadStrptrMaybe
449 static bool value61_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
450 // func:atf_amc.PmaskU128.value34.ReadStrptrMaybe
451 static bool value34_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
452 // func:atf_amc.PmaskU128.value52.ReadStrptrMaybe
453 static bool value52_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
454 // func:atf_amc.PmaskU128.value36.ReadStrptrMaybe
455 static bool value36_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
456 // func:atf_amc.PmaskU128.value37.ReadStrptrMaybe
457 static bool value37_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
458 // func:atf_amc.PmaskU128.value38.ReadStrptrMaybe
459 static bool value38_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
460 // func:atf_amc.PmaskU128.value39.ReadStrptrMaybe
461 static bool value39_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
462 // func:atf_amc.PmaskU128.value40.ReadStrptrMaybe
463 static bool value40_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
464 // func:atf_amc.PmaskU128.value41.ReadStrptrMaybe
465 static bool value41_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
466 // func:atf_amc.PmaskU128.value42.ReadStrptrMaybe
467 static bool value42_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
468 // func:atf_amc.PmaskU128.value53.ReadStrptrMaybe
469 static bool value53_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
470 // func:atf_amc.PmaskU128.value44.ReadStrptrMaybe
471 static bool value44_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
472 // func:atf_amc.PmaskU128.value45.ReadStrptrMaybe
473 static bool value45_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
474 // func:atf_amc.PmaskU128.value46.ReadStrptrMaybe
475 static bool value46_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
476 // func:atf_amc.PmaskU128.value47.ReadStrptrMaybe
477 static bool value47_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
478 // func:atf_amc.PmaskU128.value48.ReadStrptrMaybe
479 static bool value48_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
480 // func:atf_amc.PmaskU128.value49.ReadStrptrMaybe
481 static bool value49_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
482 // func:atf_amc.PmaskU128.value50.ReadStrptrMaybe
483 static bool value50_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
484 // func:atf_amc.PmaskU128.value51.ReadStrptrMaybe
485 static bool value51_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
486 // func:atf_amc.PmaskU128.value43.ReadStrptrMaybe
487 static bool value43_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
488 // func:atf_amc.PmaskU128.value70.ReadStrptrMaybe
489 static bool value70_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
490 // func:atf_amc.PmaskU128.value71.ReadStrptrMaybe
491 static bool value71_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) __attribute__((nothrow));
492 // func:atf_amc.PmaskU32.value.ReadStrptrMaybe
493 static bool value_ReadStrptrMaybe(atf_amc::PmaskU32 &parent, algo::strptr in_str) __attribute__((nothrow));
494 // func:atf_amc.PmaskU32.value2.ReadStrptrMaybe
495 static bool value2_ReadStrptrMaybe(atf_amc::PmaskU32 &parent, algo::strptr in_str) __attribute__((nothrow));
496 // func:atf_amc.PmaskU32.value3.ReadStrptrMaybe
497 static bool value3_ReadStrptrMaybe(atf_amc::PmaskU32 &parent, algo::strptr in_str) __attribute__((nothrow));
498 // func:atf_amc.PmaskU32.value4.ReadStrptrMaybe
499 static bool value4_ReadStrptrMaybe(atf_amc::PmaskU32 &parent, algo::strptr in_str) __attribute__((nothrow));
500 // func:atf_amc.PmaskU32.value5.ReadStrptrMaybe
501 static bool value5_ReadStrptrMaybe(atf_amc::PmaskU32 &parent, algo::strptr in_str) __attribute__((nothrow));
502 // Extract next character from STR and advance IDX
503 // func:atf_amc.SortedStr.novs.Nextchar
504 static int novs_Nextchar(const atf_amc::SortedStr& parent, algo::strptr &str, int &idx) __attribute__((nothrow));
505 // Extract next character from STR and advance IDX
506 // func:atf_amc.SortedStr.vs.Nextchar
507 static u64 vs_Nextchar(const atf_amc::SortedStr& parent, algo::strptr &str, int &idx) __attribute__((nothrow));
508 // func:atf_amc.TypeBE64.value.ReadStrptrMaybe
509 static bool value_ReadStrptrMaybe(atf_amc::TypeBE64 &parent, algo::strptr in_str) __attribute__((nothrow));
510 // Swap values elem_a and elem_b
511 // func:atf_amc.VarlenH.typeh.Swap
512 static void typeh_Swap(atf_amc::TypeH &elem_a, atf_amc::TypeH &elem_b) __attribute__((nothrow));
513 // Left circular shift of three-tuple
514 // func:atf_amc.VarlenH.typeh.Rotleft
515 static void typeh_Rotleft(atf_amc::TypeH &elem_a, atf_amc::TypeH &elem_b, atf_amc::TypeH &elem_c) __attribute__((nothrow));
516 // Compare values elem_a and elem_b
517 // The comparison function must be anti-symmetric: if a>b, then !(b>a).
518 // If not, mayhem results.
519 // func:atf_amc.VarlenH.typeh.Lt
520 static bool typeh_Lt(atf_amc::TypeH &elem_a, atf_amc::TypeH &elem_b) __attribute__((nothrow));
521 // Internal insertion sort
522 // func:atf_amc.VarlenH.typeh.IntInsertionSort
523 static void typeh_IntInsertionSort(atf_amc::TypeH *elems, int n) __attribute__((nothrow));
524 // Internal heap sort
525 // func:atf_amc.VarlenH.typeh.IntHeapSort
526 static void typeh_IntHeapSort(atf_amc::TypeH *elems, int n) __attribute__((nothrow));
527 // Quick sort engine
528 // func:atf_amc.VarlenH.typeh.IntQuickSort
529 static void typeh_IntQuickSort(atf_amc::TypeH *elems, int n, int depth) __attribute__((nothrow));
530 // func:atf_amc...SizeCheck
531 static void SizeCheck();
532} // gen:ns_print_proto
533
534// --- atf_amc.AmcCleanup2..Uninit
535void atf_amc::AmcCleanup2_Uninit(atf_amc::AmcCleanup2& parent) {
536 atf_amc::AmcCleanup2 &row = parent; (void)row;
537 field2_Cleanup(parent); // dmmeta.fcleanup:atf_amc.AmcCleanup2.field2
538 field1_Cleanup(parent); // dmmeta.fcleanup:atf_amc.AmcCleanup2.field1
539}
540
541// --- atf_amc.AmcSubstr1.boolval.Get
542bool atf_amc::boolval_Get(atf_amc::AmcSubstr1& parent) {
543 bool ret;
544 ret = false; // default value
545 (void)bool_ReadStrptrMaybe(ret, algo::Pathcomp(parent.strval, ".LR"));
546 return ret;
547}
548
549// --- atf_amc.AmcSubstr1.intval.Get
550i32 atf_amc::intval_Get(atf_amc::AmcSubstr1& parent) {
551 i32 ret;
552 ret = 0; // default value
553 (void)i32_ReadStrptrMaybe(ret, algo::Pathcomp(parent.strval, ".LR"));
554 return ret;
555}
556
557// --- atf_amc.BitfldType1.bit1.ReadStrptrMaybe
558inline static bool atf_amc::bit1_ReadStrptrMaybe(atf_amc::BitfldType1 &parent, algo::strptr in_str) {
559 bool retval = true;
560 u64 bit1_tmp;
561 retval = u64_ReadStrptrMaybe(bit1_tmp, in_str);
562 if (retval) {
563 bit1_Set(parent, bit1_tmp);
564 }
565 return retval;
566}
567
568// --- atf_amc.BitfldType1.bits5.ReadStrptrMaybe
569inline static bool atf_amc::bits5_ReadStrptrMaybe(atf_amc::BitfldType1 &parent, algo::strptr in_str) {
570 bool retval = true;
571 u64 bits5_tmp;
572 retval = u64_ReadStrptrMaybe(bits5_tmp, in_str);
573 if (retval) {
574 bits5_Set(parent, bits5_tmp);
575 }
576 return retval;
577}
578
579// --- atf_amc.BitfldType1..ReadFieldMaybe
580bool atf_amc::BitfldType1_ReadFieldMaybe(atf_amc::BitfldType1& parent, algo::strptr field, algo::strptr strval) {
581 bool retval = true;
582 atf_amc::FieldId field_id;
583 (void)value_SetStrptrMaybe(field_id,field);
584 switch(field_id) {
585 case atf_amc_FieldId_value: {
586 retval = u64_ReadStrptrMaybe(parent.value, strval);
587 break;
588 }
589 case atf_amc_FieldId_bit1: {
590 retval = bit1_ReadStrptrMaybe(parent, strval);
591 break;
592 }
593 case atf_amc_FieldId_bits5: {
594 retval = bits5_ReadStrptrMaybe(parent, strval);
595 break;
596 }
597 default: break;
598 }
599 if (!retval) {
600 algo_lib::AppendErrtext("attr",field);
601 }
602 return retval;
603}
604
605// --- atf_amc.BitfldType1..ReadStrptrMaybe
606// Read fields of atf_amc::BitfldType1 from an ascii string.
607// The format of the string is an ssim Tuple
608bool atf_amc::BitfldType1_ReadStrptrMaybe(atf_amc::BitfldType1 &parent, algo::strptr in_str) {
609 bool retval = true;
610 retval = algo::StripTypeTag(in_str, "atf_amc.BitfldType1");
611 ind_beg(algo::Attr_curs, attr, in_str) {
612 retval = retval && BitfldType1_ReadFieldMaybe(parent, attr.name, attr.value);
613 }ind_end;
614 return retval;
615}
616
617// --- atf_amc.BitfldType1..Print
618// print string representation of ROW to string STR
619// cfmt:atf_amc.BitfldType1.String printfmt:Tuple
620void atf_amc::BitfldType1_Print(atf_amc::BitfldType1& row, algo::cstring& str) {
621 algo::tempstr temp;
622 str << "atf_amc.BitfldType1";
623
624 u64_Print(bit1_Get(row), temp);
625 PrintAttrSpaceReset(str,"bit1", temp);
626
627 u64_Print(bits5_Get(row), temp);
628 PrintAttrSpaceReset(str,"bits5", temp);
629}
630
631// --- atf_amc.BitfldType2.bit0.ReadStrptrMaybe
632inline static bool atf_amc::bit0_ReadStrptrMaybe(atf_amc::BitfldType2 &parent, algo::strptr in_str) {
633 bool retval = true;
634 bool bit0_tmp;
635 retval = bool_ReadStrptrMaybe(bit0_tmp, in_str);
636 if (retval) {
637 bit0_Set(parent, bit0_tmp);
638 }
639 return retval;
640}
641
642// --- atf_amc.BitfldType2.bit1.ReadStrptrMaybe
643inline static bool atf_amc::bit1_ReadStrptrMaybe(atf_amc::BitfldType2 &parent, algo::strptr in_str) {
644 bool retval = true;
645 bool bit1_tmp;
646 retval = bool_ReadStrptrMaybe(bit1_tmp, in_str);
647 if (retval) {
648 bit1_Set(parent, bit1_tmp);
649 }
650 return retval;
651}
652
653// --- atf_amc.BitfldType2..ReadFieldMaybe
654bool atf_amc::BitfldType2_ReadFieldMaybe(atf_amc::BitfldType2& parent, algo::strptr field, algo::strptr strval) {
655 bool retval = true;
656 atf_amc::FieldId field_id;
657 (void)value_SetStrptrMaybe(field_id,field);
658 switch(field_id) {
659 case atf_amc_FieldId_value: {
660 retval = u64_ReadStrptrMaybe(parent.value, strval);
661 break;
662 }
663 case atf_amc_FieldId_bit0: {
664 retval = bit0_ReadStrptrMaybe(parent, strval);
665 break;
666 }
667 case atf_amc_FieldId_bit1: {
668 retval = bit1_ReadStrptrMaybe(parent, strval);
669 break;
670 }
671 case atf_amc_FieldId_freebool: {
672 retval = bool_ReadStrptrMaybe(parent.freebool, strval);
673 break;
674 }
675 default: break;
676 }
677 if (!retval) {
678 algo_lib::AppendErrtext("attr",field);
679 }
680 return retval;
681}
682
683// --- atf_amc.BitfldType2..ReadStrptrMaybe
684// Read fields of atf_amc::BitfldType2 from an ascii string.
685bool atf_amc::BitfldType2_ReadStrptrMaybe(atf_amc::BitfldType2 &parent, algo::strptr in_str) {
686 bool retval = true;
687 // Clear affected bits first)
688 bit0_Set(parent, false);
689 bit1_Set(parent, false);
690 parent.freebool = false;
691 // Read ','-separated list of bools
692 while (ch_N(in_str)) {
693 strptr field_name;
694 algo::NextSep(in_str,',',field_name);
695 field_name = algo::Trimmed(field_name);
696 if (ch_N(field_name)) {
697 atf_amc::FieldId field_id;
698 bool ok = atf_amc::value_SetStrptrMaybe(field_id,field_name);
699 if (ok) {
700 switch (field_id) {
701 case atf_amc_FieldId_bit0: {
702 bit0_Set(parent, true);
703 } break;
704 case atf_amc_FieldId_bit1: {
705 bit1_Set(parent, true);
706 } break;
707 case atf_amc_FieldId_freebool: {
708 parent.freebool = true;
709 } break;
710 default: ok = false; break;
711 }
712 }
713 if (!ok) {
714 algo_lib::AppendErrtext("bitfld",field_name);
715 retval = false;
716 }
717 }
718 }
719 return retval;
720}
721
722// --- atf_amc.BitfldType2..Print
723// print string representation of ROW to string STR
724// cfmt:atf_amc.BitfldType2.String printfmt:Bitset
725void atf_amc::BitfldType2_Print(atf_amc::BitfldType2& row, algo::cstring& str) {
726 algo::ListSep ls(",");
727 if (bit0_Get(row)) {
728 str << ls << "bit0";
729 }
730 if (bit1_Get(row)) {
731 str << ls << "bit1";
732 }
733 if (row.freebool) {
734 str << ls << "freebool";
735 }
736}
737
738// --- atf_amc.Bitset.fld1.ReadStrptrMaybe
739// Read array from string
740// Convert string to field. Return success value
741bool atf_amc::fld1_ReadStrptrMaybe(atf_amc::Bitset& parent, algo::strptr in_str) {
742 bool retval = true;
743 if (4>0) {
744 retval = u16_ReadStrptrMaybe(parent.fld1_elems[0], in_str);
745 }
746 return retval;
747}
748
749// --- atf_amc.Bitset.fld1_bitcurs.Next
750// proceed to next item
751void atf_amc::Bitset_fld1_bitcurs_Next(Bitset_fld1_bitcurs &curs) {
752 ++curs.bit;
753 int index = curs.bit / 16;
754 int offset = curs.bit % 16;
755 for (; index < curs.n_elems; ++index, offset = 0) {
756 u64 rest = curs.elems[index] >> offset;
757 if (rest) {
758 offset += algo::u64_BitScanForward(rest);
759 break;
760 }
761 }
762 curs.bit = index * 16 + offset;
763}
764
765// --- atf_amc.Bitset.fld8_bitcurs.Next
766// proceed to next item
767void atf_amc::Bitset_fld8_bitcurs_Next(Bitset_fld8_bitcurs &curs) {
768 ++curs.bit;
769 int index = curs.bit / 8;
770 int offset = curs.bit % 8;
771 for (; index < curs.n_elems; ++index, offset = 0) {
772 u64 rest = curs.elems[index] >> offset;
773 if (rest) {
774 offset += algo::u64_BitScanForward(rest);
775 break;
776 }
777 }
778 curs.bit = index * 8 + offset;
779}
780
781// --- atf_amc.Bitset.fld64_bitcurs.Next
782// proceed to next item
783void atf_amc::Bitset_fld64_bitcurs_Next(Bitset_fld64_bitcurs &curs) {
784 ++curs.bit;
785 int index = curs.bit / 64;
786 int offset = curs.bit % 64;
787 for (; index < curs.n_elems; ++index, offset = 0) {
788 u64 rest = curs.elems[index] >> offset;
789 if (rest) {
790 offset += algo::u64_BitScanForward(rest);
791 break;
792 }
793 }
794 curs.bit = index * 64 + offset;
795}
796
797// --- atf_amc.Bytebuf.in.GetMsg
798// Detect incoming message in buffer and return it
799// Look for valid message at current position in the buffer.
800// If message is already there, return a pointer to it. Do not skip message (call SkipMsg to do that).
801// If there is no message, read once from underlying file descriptor and try again.
802// The message is any number of bytes > 0
803//
804algo::aryptr<char> atf_amc::in_GetMsg(atf_amc::Bytebuf& bytebuf) {
805 algo::aryptr<char> ret;
806 if (in_N(bytebuf) == 0) {
807 }
808 char *hdr = (char*)(bytebuf.in_elems + bytebuf.in_start);
809 if (in_N(bytebuf)) {
810 ret.elems = hdr; // if no elements, return value is NULL
811 ret.n_elems = in_N(bytebuf);
812 }
813 return ret;
814}
815
816// --- atf_amc.Bytebuf.in.RemoveAll
817// Empty bfufer
818// Discard contents of the buffer.
819void atf_amc::in_RemoveAll(atf_amc::Bytebuf& bytebuf) {
820 bytebuf.in_start = 0;
821 bytebuf.in_end = 0;
822}
823
824// --- atf_amc.Bytebuf.in.Shift
825// Internal function to shift data left
826// Shift existing bytes over to the beginning of the buffer
827static void atf_amc::in_Shift(atf_amc::Bytebuf& bytebuf) {
828 i32 start = bytebuf.in_start;
829 i32 bytes_n = bytebuf.in_end - start;
830 if (bytes_n > 0) {
831 memmove(bytebuf.in_elems, bytebuf.in_elems + start, bytes_n);
832 }
833 bytebuf.in_end = bytes_n;
834 bytebuf.in_start = 0;
835}
836
837// --- atf_amc.Bytebuf.in.SkipBytes
838// Skip N bytes when reading
839// Mark some buffer contents as read.
840//
841void atf_amc::in_SkipBytes(atf_amc::Bytebuf& bytebuf, int n) {
842 int avail = bytebuf.in_end - bytebuf.in_start;
843 n = i32_Min(n,avail);
844 bytebuf.in_start += n;
845}
846
847// --- atf_amc.Bytebuf.in.WriteAll
848// Attempt to write buffer contents to fd
849// Write bytes to the buffer. If the entire block is written, return true,
850// Otherwise return false.
851// Bytes in the buffer are potentially shifted left to make room for the message.
852//
853bool atf_amc::in_WriteAll(atf_amc::Bytebuf& bytebuf, u8 *in, i32 in_n) {
854 int max = in_Max(bytebuf);
855 // check if message doesn't fit. if so, shift bytes over.
856 if (bytebuf.in_end + in_n > max) {
857 in_Shift(bytebuf);
858 }
859 // now try to write the message.
860 i32 end = bytebuf.in_end;
861 bool fits = end + in_n <= max;
862 if (fits && in_n > 0) {
863 memcpy(bytebuf.in_elems + end, in, in_n);
864 bytebuf.in_end = end + in_n;
865 }
866 return fits;
867}
868
869// --- atf_amc.Bytebuf..Init
870// Set all fields to initial values.
871void atf_amc::Bytebuf_Init(atf_amc::Bytebuf& bytebuf) {
872 bytebuf.in_end = 0; // in: initialize
873 bytebuf.in_start = 0; // in: initialize
874 bytebuf.in_eof = false; // in: initialize
875 bytebuf.in_epoll_enable = true; // in: initialize
876}
877
878// --- atf_amc.Bytebuf..Print
879// print string representation of ROW to string STR
880// cfmt:atf_amc.Bytebuf.String printfmt:Raw
881void atf_amc::Bytebuf_Print(atf_amc::Bytebuf& row, algo::cstring& str) {
882 (void)row;//only to avoid -Wunused-parameter
883 (void)str;//only to avoid -Wunused-parameter
884}
885
886// --- atf_amc.BytebufDyn.in.GetMsg
887// Detect incoming message in buffer and return it
888// Look for valid message at current position in the buffer.
889// If message is already there, return a pointer to it. Do not skip message (call SkipMsg to do that).
890// If there is no message, read once from underlying file descriptor and try again.
891// The message is any number of bytes > 0
892//
893algo::aryptr<char> atf_amc::in_GetMsg(atf_amc::BytebufDyn& bytebuf_dyn) {
894 algo::aryptr<char> ret;
895 if (in_N(bytebuf_dyn) == 0) {
896 }
897 char *hdr = (char*)(bytebuf_dyn.in_elems + bytebuf_dyn.in_start);
898 if (in_N(bytebuf_dyn)) {
899 ret.elems = hdr; // if no elements, return value is NULL
900 ret.n_elems = in_N(bytebuf_dyn);
901 }
902 return ret;
903}
904
905// --- atf_amc.BytebufDyn.in.Realloc
906// Set buffer size.
907// Unconditionally reallocate buffer to have size NEW_MAX
908// If the buffer has data in it, NEW_MAX is adjusted so that the data is not lost
909// (best to call this before filling the buffer)
910void atf_amc::in_Realloc(atf_amc::BytebufDyn& bytebuf_dyn, int new_max) {
911 new_max = i32_Max(new_max, bytebuf_dyn.in_end);
912 u8 *new_mem = bytebuf_dyn.in_elems
913 ? (u8*)algo_lib::malloc_ReallocMem(bytebuf_dyn.in_elems, bytebuf_dyn.in_max, new_max)
914 : (u8*)algo_lib::malloc_AllocMem(new_max);
915 if (UNLIKELY(!new_mem)) {
916 FatalErrorExit("atf_amc.fbuf_nomem field:atf_amc.BytebufDyn.in comment:'out of memory'");
917 }
918 bytebuf_dyn.in_elems = new_mem;
919 bytebuf_dyn.in_max = new_max;
920}
921
922// --- atf_amc.BytebufDyn.in.RemoveAll
923// Empty bfufer
924// Discard contents of the buffer.
925void atf_amc::in_RemoveAll(atf_amc::BytebufDyn& bytebuf_dyn) {
926 bytebuf_dyn.in_start = 0;
927 bytebuf_dyn.in_end = 0;
928}
929
930// --- atf_amc.BytebufDyn.in.Shift
931// Internal function to shift data left
932// Shift existing bytes over to the beginning of the buffer
933static void atf_amc::in_Shift(atf_amc::BytebufDyn& bytebuf_dyn) {
934 i32 start = bytebuf_dyn.in_start;
935 i32 bytes_n = bytebuf_dyn.in_end - start;
936 if (bytes_n > 0) {
937 memmove(bytebuf_dyn.in_elems, bytebuf_dyn.in_elems + start, bytes_n);
938 }
939 bytebuf_dyn.in_end = bytes_n;
940 bytebuf_dyn.in_start = 0;
941}
942
943// --- atf_amc.BytebufDyn.in.SkipBytes
944// Skip N bytes when reading
945// Mark some buffer contents as read.
946//
947void atf_amc::in_SkipBytes(atf_amc::BytebufDyn& bytebuf_dyn, int n) {
948 int avail = bytebuf_dyn.in_end - bytebuf_dyn.in_start;
949 n = i32_Min(n,avail);
950 bytebuf_dyn.in_start += n;
951}
952
953// --- atf_amc.BytebufDyn.in.WriteAll
954// Attempt to write buffer contents to fd
955// Write bytes to the buffer. If the entire block is written, return true,
956// Otherwise return false.
957// Bytes in the buffer are potentially shifted left to make room for the message.
958//
959bool atf_amc::in_WriteAll(atf_amc::BytebufDyn& bytebuf_dyn, u8 *in, i32 in_n) {
960 int max = in_Max(bytebuf_dyn);
961 // check if message doesn't fit. if so, shift bytes over.
962 if (bytebuf_dyn.in_end + in_n > max) {
963 in_Shift(bytebuf_dyn);
964 }
965 // now try to write the message.
966 i32 end = bytebuf_dyn.in_end;
967 bool fits = end + in_n <= max;
968 if (fits && in_n > 0) {
969 memcpy(bytebuf_dyn.in_elems + end, in, in_n);
970 bytebuf_dyn.in_end = end + in_n;
971 }
972 return fits;
973}
974
975// --- atf_amc.BytebufDyn..Init
976// Set all fields to initial values.
977void atf_amc::BytebufDyn_Init(atf_amc::BytebufDyn& bytebuf_dyn) {
978 bytebuf_dyn.in_elems = NULL; // in: initialize
979 bytebuf_dyn.in_max = 0; // in: initialize
980 bytebuf_dyn.in_end = 0; // in: initialize
981 bytebuf_dyn.in_start = 0; // in: initialize
982 bytebuf_dyn.in_eof = false; // in: initialize
983 bytebuf_dyn.in_epoll_enable = true; // in: initialize
984}
985
986// --- atf_amc.BytebufDyn..Uninit
987void atf_amc::BytebufDyn_Uninit(atf_amc::BytebufDyn& bytebuf_dyn) {
988 atf_amc::BytebufDyn &row = bytebuf_dyn; (void)row;
989
990 // atf_amc.BytebufDyn.in.Uninit (Fbuf) //Streaming buffer
991 if (bytebuf_dyn.in_elems) {
992 algo_lib::malloc_FreeMem(bytebuf_dyn.in_elems, sizeof(char)*bytebuf_dyn.in_max); // (atf_amc.BytebufDyn.in)
993 }
994 bytebuf_dyn.in_elems = NULL;
995 bytebuf_dyn.in_max = 0;
996}
997
998// --- atf_amc.BytebufDyn..Print
999// print string representation of ROW to string STR
1000// cfmt:atf_amc.BytebufDyn.String printfmt:Raw
1001void atf_amc::BytebufDyn_Print(atf_amc::BytebufDyn& row, algo::cstring& str) {
1002 (void)row;//only to avoid -Wunused-parameter
1003 (void)str;//only to avoid -Wunused-parameter
1004}
1005
1006// --- atf_amc.Cstr.val.Nextchar
1007// Extract next character from STR and advance IDX
1008inline static int atf_amc::val_Nextchar(const atf_amc::Cstr& parent, algo::strptr &str, int &idx) {
1009 (void)parent;
1010 int i = idx;
1011 int ch = str.elems[i];
1012 i++;
1013 idx = i;
1014 return ch;
1015}
1016
1017// --- atf_amc.Cstr..FmtJson
1018// Create JSON representation of atf_amc::Cstr under PARENT node
1019// cfmt:atf_amc.Cstr.Json printfmt:Auto
1020lib_json::FNode * atf_amc::Cstr_FmtJson(atf_amc::Cstr& row, lib_json::FNode *parent) {
1021 return algo::cstring_FmtJson(const_cast<atf_amc::Cstr&>(row).val,parent);;
1022}
1023
1024// --- atf_amc.Ctype1Attr..ReadStrptrMaybe
1025// Read fields of atf_amc::Ctype1Attr from an ascii string.
1026// The format of the string is the format of the atf_amc::Ctype1Attr's only field
1027bool atf_amc::Ctype1Attr_ReadStrptrMaybe(atf_amc::Ctype1Attr &parent, algo::strptr in_str) {
1028 bool retval = true;
1029 retval = retval && u32_ReadStrptrMaybe(parent.attr1, in_str);
1030 return retval;
1031}
1032
1033// --- atf_amc.Ctype1Attr..Print
1034// print string representation of ROW to string STR
1035// cfmt:atf_amc.Ctype1Attr.String printfmt:Raw
1036void atf_amc::Ctype1Attr_Print(atf_amc::Ctype1Attr& row, algo::cstring& str) {
1037 u32_Print(row.attr1, str);
1038}
1039
1040// --- atf_amc.Ctype2Attr..ReadFieldMaybe
1041bool atf_amc::Ctype2Attr_ReadFieldMaybe(atf_amc::Ctype2Attr& parent, algo::strptr field, algo::strptr strval) {
1042 bool retval = true;
1043 atf_amc::FieldId field_id;
1044 (void)value_SetStrptrMaybe(field_id,field);
1045 switch(field_id) {
1046 case atf_amc_FieldId_attr1: {
1047 retval = u32_ReadStrptrMaybe(parent.attr1, strval);
1048 break;
1049 }
1050 case atf_amc_FieldId_attr2: {
1051 retval = u32_ReadStrptrMaybe(parent.attr2, strval);
1052 break;
1053 }
1054 default: break;
1055 }
1056 if (!retval) {
1057 algo_lib::AppendErrtext("attr",field);
1058 }
1059 return retval;
1060}
1061
1062// --- atf_amc.Ctype2Attr..ReadStrptrMaybe
1063// Read fields of atf_amc::Ctype2Attr from an ascii string.
1064// The format of the string is an ssim Tuple
1065bool atf_amc::Ctype2Attr_ReadStrptrMaybe(atf_amc::Ctype2Attr &parent, algo::strptr in_str) {
1066 bool retval = true;
1067 retval = algo::StripTypeTag(in_str, "atf_amc.Ctype2Attr");
1068 ind_beg(algo::Attr_curs, attr, in_str) {
1069 retval = retval && Ctype2Attr_ReadFieldMaybe(parent, attr.name, attr.value);
1070 }ind_end;
1071 return retval;
1072}
1073
1074// --- atf_amc.Ctype2Attr..ReadTupleMaybe
1075// Read fields of atf_amc::Ctype2Attr from attributes of ascii tuple TUPLE
1076bool atf_amc::Ctype2Attr_ReadTupleMaybe(atf_amc::Ctype2Attr &parent, algo::Tuple &tuple) {
1077 bool retval = true;
1078 ind_beg(algo::Tuple_attrs_curs,attr,tuple) {
1079 retval = Ctype2Attr_ReadFieldMaybe(parent, attr.name, attr.value);
1080 if (!retval) {
1081 break;
1082 }
1083 }ind_end;
1084 return retval;
1085}
1086
1087// --- atf_amc.Ctype2Attr..Print
1088// print string representation of ROW to string STR
1089// cfmt:atf_amc.Ctype2Attr.String printfmt:Tuple
1090void atf_amc::Ctype2Attr_Print(atf_amc::Ctype2Attr& row, algo::cstring& str) {
1091 algo::tempstr temp;
1092 str << "atf_amc.Ctype2Attr";
1093
1094 u32_Print(row.attr1, temp);
1095 PrintAttrSpaceReset(str,"attr1", temp);
1096
1097 u32_Print(row.attr2, temp);
1098 PrintAttrSpaceReset(str,"attr2", temp);
1099}
1100
1101// --- atf_amc.Ctype2AttrAnon..ReadFieldMaybe
1102bool atf_amc::Ctype2AttrAnon_ReadFieldMaybe(atf_amc::Ctype2AttrAnon& parent, algo::strptr field, algo::strptr strval) {
1103 bool retval = true;
1104 atf_amc::FieldId field_id;
1105 (void)value_SetStrptrMaybe(field_id,field);
1106 switch(field_id) {
1107 case atf_amc_FieldId_attr1: {
1108 retval = u32_ReadStrptrMaybe(parent.attr1, strval);
1109 break;
1110 }
1111 case atf_amc_FieldId_attr2: {
1112 retval = u32_ReadStrptrMaybe(parent.attr2, strval);
1113 break;
1114 }
1115 default: break;
1116 }
1117 if (!retval) {
1118 algo_lib::AppendErrtext("attr",field);
1119 }
1120 return retval;
1121}
1122
1123// --- atf_amc.Ctype2AttrAnon..ReadStrptrMaybe
1124// Read fields of atf_amc::Ctype2AttrAnon from an ascii string.
1125// The format of the string is an ssim Tuple
1126bool atf_amc::Ctype2AttrAnon_ReadStrptrMaybe(atf_amc::Ctype2AttrAnon &parent, algo::strptr in_str) {
1127 bool retval = true;
1128 retval = algo::StripTypeTag(in_str, "atf_amc.Ctype2AttrAnon");
1129 int anon_idx = 0;
1130 ind_beg(algo::Attr_curs, attr, in_str) {
1131 if (ch_N(attr.name) == 0) {
1132 attr.name = Ctype2AttrAnon_GetAnon(parent, anon_idx++);
1133 }
1134 retval = retval && Ctype2AttrAnon_ReadFieldMaybe(parent, attr.name, attr.value);
1135 }ind_end;
1136 return retval;
1137}
1138
1139// --- atf_amc.Ctype2AttrAnon..Print
1140// print string representation of ROW to string STR
1141// cfmt:atf_amc.Ctype2AttrAnon.String printfmt:Tuple
1142void atf_amc::Ctype2AttrAnon_Print(atf_amc::Ctype2AttrAnon& row, algo::cstring& str) {
1143 algo::tempstr temp;
1144 str << "atf_amc.Ctype2AttrAnon";
1145
1146 u32_Print(row.attr1, temp);
1147 PrintAttrSpaceReset(str,"attr1", temp);
1148
1149 u32_Print(row.attr2, temp);
1150 PrintAttrSpaceReset(str,"attr2", temp);
1151}
1152
1153// --- atf_amc.Ctype2AttrAnon..GetAnon
1154algo::strptr atf_amc::Ctype2AttrAnon_GetAnon(atf_amc::Ctype2AttrAnon &parent, i32 idx) {
1155 (void)parent;//only to avoid -Wunused-parameter
1156 switch(idx) {
1157 case(0): return strptr("attr1", 5);
1158 case(1): return strptr("attr2", 5);
1159 default: return algo::strptr();
1160 }
1161}
1162
1163// --- atf_amc.DelType1.u32val.Access
1164// Get or Create
1165// Access value, creating it if necessary. Process dies if not successful.
1166u32& atf_amc::u32val_Access(atf_amc::DelType1& parent) {
1167 u32 *ret=parent.u32val;
1168 if (!ret) {
1169 ret = (u32*)algo_lib::malloc_AllocMem(sizeof(u32));
1170 if (!ret) {
1171 FatalErrorExit("out of memory allocating u32 (in atf_amc::DelType1.u32val)");
1172 }
1173 new(ret) u32(34);
1174 parent.u32val = ret;
1175 }
1176 return *ret;
1177}
1178
1179// --- atf_amc.DelType1.u32val.Delete
1180// Delete value.
1181void atf_amc::u32val_Delete(atf_amc::DelType1& parent) {
1182 if (parent.u32val) {
1183 algo_lib::malloc_FreeMem(parent.u32val, sizeof(u32));
1184 parent.u32val = NULL;
1185 }
1186}
1187
1188// --- atf_amc.DelType1..Uninit
1189void atf_amc::DelType1_Uninit(atf_amc::DelType1& parent) {
1190 atf_amc::DelType1 &row = parent; (void)row;
1191
1192 // atf_amc.DelType1.u32val.Uninit (Delptr) //
1193 u32val_Delete(parent);
1194}
1195
1196// --- atf_amc.DispCase.value.ToCstr
1197// Convert numeric value of field to one of predefined string constants.
1198// If string is found, return a static C string. Otherwise, return NULL.
1199const char* atf_amc::value_ToCstr(const atf_amc::DispCase& parent) {
1200 const char *ret = NULL;
1201 switch(value_GetEnum(parent)) {
1202 case atf_amc_DispCase_atf_amc_DispType1: ret = "atf_amc.DispType1"; break;
1203 case atf_amc_DispCase_atf_amc_DispType2: ret = "atf_amc.DispType2"; break;
1204 case atf_amc_DispCase_atf_amc_DispType3: ret = "atf_amc.DispType3"; break;
1205 }
1206 return ret;
1207}
1208
1209// --- atf_amc.DispCase.value.Print
1210// Convert value to a string. First, attempt conversion to a known string.
1211// If no string matches, print value as a numeric value.
1212void atf_amc::value_Print(const atf_amc::DispCase& parent, algo::cstring &lhs) {
1213 const char *strval = value_ToCstr(parent);
1214 if (strval) {
1215 lhs << strval;
1216 } else {
1217 lhs << parent.value;
1218 }
1219}
1220
1221// --- atf_amc.DispCase.value.SetStrptrMaybe
1222// Convert string to field.
1223// If the string is invalid, do not modify field and return false.
1224// In case of success, return true
1225bool atf_amc::value_SetStrptrMaybe(atf_amc::DispCase& parent, algo::strptr rhs) {
1226 bool ret = false;
1227 switch (elems_N(rhs)) {
1228 case 17: {
1229 switch (algo::ReadLE64(rhs.elems)) {
1230 case LE_STR8('a','t','f','_','a','m','c','.'): {
1231 if (memcmp(rhs.elems+8,"DispType1",9)==0) { value_SetEnum(parent,atf_amc_DispCase_atf_amc_DispType1); ret = true; break; }
1232 if (memcmp(rhs.elems+8,"DispType2",9)==0) { value_SetEnum(parent,atf_amc_DispCase_atf_amc_DispType2); ret = true; break; }
1233 if (memcmp(rhs.elems+8,"DispType3",9)==0) { value_SetEnum(parent,atf_amc_DispCase_atf_amc_DispType3); ret = true; break; }
1234 break;
1235 }
1236 }
1237 break;
1238 }
1239 }
1240 return ret;
1241}
1242
1243// --- atf_amc.DispCase.value.SetStrptr
1244// Convert string to field.
1245// If the string is invalid, set numeric value to DFLT
1246void atf_amc::value_SetStrptr(atf_amc::DispCase& parent, algo::strptr rhs, atf_amc_DispCaseEnum dflt) {
1247 if (!value_SetStrptrMaybe(parent,rhs)) value_SetEnum(parent,dflt);
1248}
1249
1250// --- atf_amc.DispCase.value.ReadStrptrMaybe
1251// Convert string to field. Return success value
1252bool atf_amc::value_ReadStrptrMaybe(atf_amc::DispCase& parent, algo::strptr rhs) {
1253 bool retval = false;
1254 retval = value_SetStrptrMaybe(parent,rhs); // try symbol conversion
1255 if (!retval) { // didn't work? try reading as underlying type
1256 retval = u32_ReadStrptrMaybe(parent.value,rhs);
1257 }
1258 return retval;
1259}
1260
1261// --- atf_amc.DispCase..ReadStrptrMaybe
1262// Read fields of atf_amc::DispCase from an ascii string.
1263// The format of the string is the format of the atf_amc::DispCase's only field
1264bool atf_amc::DispCase_ReadStrptrMaybe(atf_amc::DispCase &parent, algo::strptr in_str) {
1265 bool retval = true;
1266 retval = retval && value_ReadStrptrMaybe(parent, in_str);
1267 return retval;
1268}
1269
1270// --- atf_amc.DispFilter.pmask.ReadStrptrMaybe
1271// Read array from string
1272// Convert string to field. Return success value
1273bool atf_amc::pmask_ReadStrptrMaybe(atf_amc::DispFilter& parent, algo::strptr in_str) {
1274 bool retval = true;
1275 if (1>0) {
1276 retval = u64_ReadStrptrMaybe(parent.pmask_elems[0], in_str);
1277 }
1278 return retval;
1279}
1280
1281// --- atf_amc.DispFilter.strval.ReadStrptrMaybe
1282inline static bool atf_amc::strval_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) {
1283 bool retval = true;
1284 algo::Smallstr20 strval_tmp;
1285 retval = algo::Smallstr20_ReadStrptrMaybe(strval_tmp, in_str);
1286 if (retval) {
1287 strval_Set(parent, strval_tmp);
1288 }
1289 return retval;
1290}
1291
1292// --- atf_amc.DispFilter.strval_regx.ReadStrptrMaybe
1293inline static bool atf_amc::strval_regx_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) {
1294 bool retval = true;
1295 retval = algo_lib::Regx_ReadStrptrMaybe(parent.strval_regx, in_str);
1296 strval_regx_SetPresent(parent);
1297 return retval;
1298}
1299
1300// --- atf_amc.DispFilter.strval2.ReadStrptrMaybe
1301inline static bool atf_amc::strval2_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) {
1302 bool retval = true;
1303 algo::Smallstr20 strval2_tmp;
1304 retval = algo::Smallstr20_ReadStrptrMaybe(strval2_tmp, in_str);
1305 if (retval) {
1306 strval2_Set(parent, strval2_tmp);
1307 }
1308 return retval;
1309}
1310
1311// --- atf_amc.DispFilter.strval2_regx.ReadStrptrMaybe
1312inline static bool atf_amc::strval2_regx_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) {
1313 bool retval = true;
1314 retval = algo_lib::Regx_ReadStrptrMaybe(parent.strval2_regx, in_str);
1315 strval2_regx_SetPresent(parent);
1316 return retval;
1317}
1318
1319// --- atf_amc.DispFilter.start_dateval.ReadStrptrMaybe
1320inline static bool atf_amc::start_dateval_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) {
1321 bool retval = true;
1322 algo::UnTime start_dateval_tmp;
1323 retval = algo::UnTime_ReadStrptrMaybe(start_dateval_tmp, in_str);
1324 if (retval) {
1325 start_dateval_Set(parent, start_dateval_tmp);
1326 }
1327 return retval;
1328}
1329
1330// --- atf_amc.DispFilter.end_dateval.ReadStrptrMaybe
1331inline static bool atf_amc::end_dateval_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) {
1332 bool retval = true;
1333 algo::UnTime end_dateval_tmp;
1334 retval = algo::UnTime_ReadStrptrMaybe(end_dateval_tmp, in_str);
1335 if (retval) {
1336 end_dateval_Set(parent, end_dateval_tmp);
1337 }
1338 return retval;
1339}
1340
1341// --- atf_amc.DispFilter.dateval.ReadStrptrMaybe
1342inline static bool atf_amc::dateval_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) {
1343 bool retval = true;
1344 algo::UnTime dateval_tmp;
1345 retval = algo::UnTime_ReadStrptrMaybe(dateval_tmp, in_str);
1346 if (retval) {
1347 dateval_Set(parent, dateval_tmp);
1348 }
1349 return retval;
1350}
1351
1352// --- atf_amc.DispFilter.start_intval.ReadStrptrMaybe
1353inline static bool atf_amc::start_intval_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) {
1354 bool retval = true;
1355 u32 start_intval_tmp;
1356 retval = u32_ReadStrptrMaybe(start_intval_tmp, in_str);
1357 if (retval) {
1358 start_intval_Set(parent, start_intval_tmp);
1359 }
1360 return retval;
1361}
1362
1363// --- atf_amc.DispFilter.end_intval.ReadStrptrMaybe
1364inline static bool atf_amc::end_intval_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) {
1365 bool retval = true;
1366 u32 end_intval_tmp;
1367 retval = u32_ReadStrptrMaybe(end_intval_tmp, in_str);
1368 if (retval) {
1369 end_intval_Set(parent, end_intval_tmp);
1370 }
1371 return retval;
1372}
1373
1374// --- atf_amc.DispFilter.intval.ReadStrptrMaybe
1375inline static bool atf_amc::intval_ReadStrptrMaybe(atf_amc::DispFilter &parent, algo::strptr in_str) {
1376 bool retval = true;
1377 u32 intval_tmp;
1378 retval = u32_ReadStrptrMaybe(intval_tmp, in_str);
1379 if (retval) {
1380 intval_Set(parent, intval_tmp);
1381 }
1382 return retval;
1383}
1384
1385// --- atf_amc.DispFilter.pmask_bitcurs.Next
1386// proceed to next item
1387void atf_amc::DispFilter_pmask_bitcurs_Next(DispFilter_pmask_bitcurs &curs) {
1388 ++curs.bit;
1389 int index = curs.bit / 64;
1390 int offset = curs.bit % 64;
1391 for (; index < curs.n_elems; ++index, offset = 0) {
1392 u64 rest = curs.elems[index] >> offset;
1393 if (rest) {
1394 offset += algo::u64_BitScanForward(rest);
1395 break;
1396 }
1397 }
1398 curs.bit = index * 64 + offset;
1399}
1400
1401// --- atf_amc.DispFilter..ReadFieldMaybe
1402bool atf_amc::DispFilter_ReadFieldMaybe(atf_amc::DispFilter& parent, algo::strptr field, algo::strptr strval) {
1403 bool retval = true;
1404 atf_amc::FieldId field_id;
1405 (void)value_SetStrptrMaybe(field_id,algo::Pathcomp(field, ".LL"));
1406 switch(field_id) {
1407 case atf_amc_FieldId_pmask: {
1408 retval = pmask_ReadStrptrMaybe(parent, strval);
1409 break;
1410 }
1411 case atf_amc_FieldId_strval: {
1412 retval = strval_ReadStrptrMaybe(parent, strval);
1413 if (retval) {
1414 pmask_qSetBit(parent, 0);
1415 }
1416 break;
1417 }
1418 case atf_amc_FieldId_strval_regx: {
1419 retval = strval_regx_ReadStrptrMaybe(parent, strval);
1420 if (retval) {
1421 pmask_qSetBit(parent, 1);
1422 }
1423 break;
1424 }
1425 case atf_amc_FieldId_strval2: {
1426 retval = strval2_ReadStrptrMaybe(parent, strval);
1427 if (retval) {
1428 pmask_qSetBit(parent, 2);
1429 }
1430 break;
1431 }
1432 case atf_amc_FieldId_strval2_regx: {
1433 retval = strval2_regx_ReadStrptrMaybe(parent, strval);
1434 if (retval) {
1435 pmask_qSetBit(parent, 3);
1436 }
1437 break;
1438 }
1439 case atf_amc_FieldId_start_dateval: {
1440 retval = start_dateval_ReadStrptrMaybe(parent, strval);
1441 if (retval) {
1442 pmask_qSetBit(parent, 4);
1443 }
1444 break;
1445 }
1446 case atf_amc_FieldId_end_dateval: {
1447 retval = end_dateval_ReadStrptrMaybe(parent, strval);
1448 if (retval) {
1449 pmask_qSetBit(parent, 5);
1450 }
1451 break;
1452 }
1453 case atf_amc_FieldId_dateval: {
1454 retval = dateval_ReadStrptrMaybe(parent, strval);
1455 if (retval) {
1456 pmask_qSetBit(parent, 6);
1457 }
1458 break;
1459 }
1460 case atf_amc_FieldId_start_intval: {
1461 retval = start_intval_ReadStrptrMaybe(parent, strval);
1462 if (retval) {
1463 pmask_qSetBit(parent, 7);
1464 }
1465 break;
1466 }
1467 case atf_amc_FieldId_end_intval: {
1468 retval = end_intval_ReadStrptrMaybe(parent, strval);
1469 if (retval) {
1470 pmask_qSetBit(parent, 8);
1471 }
1472 break;
1473 }
1474 case atf_amc_FieldId_intval: {
1475 retval = intval_ReadStrptrMaybe(parent, strval);
1476 if (retval) {
1477 pmask_qSetBit(parent, 9);
1478 }
1479 break;
1480 }
1481 default: break;
1482 }
1483 if (!retval) {
1484 algo_lib::AppendErrtext("attr",field);
1485 }
1486 return retval;
1487}
1488
1489// --- atf_amc.DispFilter..ReadTupleMaybe
1490// Read fields of atf_amc::DispFilter from attributes of ascii tuple TUPLE
1491bool atf_amc::DispFilter_ReadTupleMaybe(atf_amc::DispFilter &parent, algo::Tuple &tuple) {
1492 bool retval = true;
1493 ind_beg(algo::Tuple_attrs_curs,attr,tuple) {
1494 retval = DispFilter_ReadFieldMaybe(parent, attr.name, attr.value);
1495 if (!retval) {
1496 break;
1497 }
1498 }ind_end;
1499 return retval;
1500}
1501
1502// --- atf_amc.DispFilter..Init
1503// Set all fields to initial values.
1504void atf_amc::DispFilter_Init(atf_amc::DispFilter& parent) {
1505 for (int i = 0; i < 1; i++) {
1506 parent.pmask_elems[i] = 0;
1507 }
1508 parent.start_intval = u32(0);
1509 parent.end_intval = u32(0);
1510 parent.intval = u32(0);
1511}
1512
1513// --- atf_amc.DispFilter..MatchDispType1
1514bool atf_amc::DispFilter_MatchDispType1(atf_amc::DispFilter &parent, atf_amc::DispType1 &msg) {
1515 bool ret = true;
1516 tempstr fieldstr;
1517 if (strval_PresentQ(parent) && !(msg.strval == parent.strval)) {
1518 return false;
1519 }
1520 if (strval_regx_PresentQ(parent)) {
1521 ch_RemoveAll(fieldstr);
1522 Smallstr20_Print(msg.strval, fieldstr);
1523 if (!algo_lib::Regx_Match(parent.strval_regx, fieldstr)) {
1524 return false;
1525 }
1526 }
1527 if (strval2_PresentQ(parent) && !(msg.strval2 == parent.strval2)) {
1528 return false;
1529 }
1530 if (strval2_regx_PresentQ(parent)) {
1531 ch_RemoveAll(fieldstr);
1532 Smallstr20_Print(msg.strval2, fieldstr);
1533 if (!algo_lib::Regx_Match(parent.strval2_regx, fieldstr)) {
1534 return false;
1535 }
1536 }
1537 if (dateval_PresentQ(parent) && !(msg.dateval == parent.dateval)) {
1538 return false;
1539 }
1540 if (start_dateval_PresentQ(parent) && msg.dateval < parent.start_dateval) {
1541 return false;
1542 }
1543 if (end_dateval_PresentQ(parent) && parent.end_dateval < msg.dateval) {
1544 return false;
1545 }
1546 return ret;
1547}
1548
1549// --- atf_amc.DispFilter..MatchDispType2
1550bool atf_amc::DispFilter_MatchDispType2(atf_amc::DispFilter &parent, atf_amc::DispType2 &msg) {
1551 bool ret = true;
1552 tempstr fieldstr;
1553 if (intval_PresentQ(parent) && !(msg.intval == parent.intval)) {
1554 return false;
1555 }
1556 if (start_intval_PresentQ(parent) && msg.intval < parent.start_intval) {
1557 return false;
1558 }
1559 if (end_intval_PresentQ(parent) && parent.end_intval < msg.intval) {
1560 return false;
1561 }
1562 return ret;
1563}
1564
1565// --- atf_amc.DispFilter..MatchDispType3
1566bool atf_amc::DispFilter_MatchDispType3(atf_amc::DispFilter &parent, atf_amc::DispType3 &msg) {
1567 bool ret = true;
1568 tempstr fieldstr;
1569 if (intval_PresentQ(parent) && !(msg.intval == parent.intval)) {
1570 return false;
1571 }
1572 if (start_intval_PresentQ(parent) && msg.intval < parent.start_intval) {
1573 return false;
1574 }
1575 if (end_intval_PresentQ(parent) && parent.end_intval < msg.intval) {
1576 return false;
1577 }
1578 if (strval_PresentQ(parent) && !(msg.strval == parent.strval)) {
1579 return false;
1580 }
1581 if (strval_regx_PresentQ(parent)) {
1582 ch_RemoveAll(fieldstr);
1583 Smallstr20_Print(msg.strval, fieldstr);
1584 if (!algo_lib::Regx_Match(parent.strval_regx, fieldstr)) {
1585 return false;
1586 }
1587 }
1588 return ret;
1589}
1590
1591// --- atf_amc.DispType1..ReadFieldMaybe
1592bool atf_amc::DispType1_ReadFieldMaybe(atf_amc::DispType1& parent, algo::strptr field, algo::strptr strval) {
1593 bool retval = true;
1594 atf_amc::FieldId field_id;
1595 (void)value_SetStrptrMaybe(field_id,field);
1596 switch(field_id) {
1597 case atf_amc_FieldId_strval: {
1598 retval = algo::Smallstr20_ReadStrptrMaybe(parent.strval, strval);
1599 break;
1600 }
1601 case atf_amc_FieldId_strval2: {
1602 retval = algo::Smallstr20_ReadStrptrMaybe(parent.strval2, strval);
1603 break;
1604 }
1605 case atf_amc_FieldId_dateval: {
1606 retval = algo::UnTime_ReadStrptrMaybe(parent.dateval, strval);
1607 break;
1608 }
1609 default: break;
1610 }
1611 if (!retval) {
1612 algo_lib::AppendErrtext("attr",field);
1613 }
1614 return retval;
1615}
1616
1617// --- atf_amc.DispType1..ReadStrptrMaybe
1618// Read fields of atf_amc::DispType1 from an ascii string.
1619// The format of the string is an ssim Tuple
1620bool atf_amc::DispType1_ReadStrptrMaybe(atf_amc::DispType1 &parent, algo::strptr in_str) {
1621 bool retval = true;
1622 retval = algo::StripTypeTag(in_str, "atf_amc.DispType1");
1623 ind_beg(algo::Attr_curs, attr, in_str) {
1624 retval = retval && DispType1_ReadFieldMaybe(parent, attr.name, attr.value);
1625 }ind_end;
1626 return retval;
1627}
1628
1629// --- atf_amc.DispType1..Print
1630// print string representation of ROW to string STR
1631// cfmt:atf_amc.DispType1.String printfmt:Tuple
1632void atf_amc::DispType1_Print(atf_amc::DispType1& row, algo::cstring& str) {
1633 algo::tempstr temp;
1634 str << "atf_amc.DispType1";
1635
1636 algo::Smallstr20_Print(row.strval, temp);
1637 PrintAttrSpaceReset(str,"strval", temp);
1638
1639 algo::Smallstr20_Print(row.strval2, temp);
1640 PrintAttrSpaceReset(str,"strval2", temp);
1641
1642 algo::UnTime_Print(row.dateval, temp);
1643 PrintAttrSpaceReset(str,"dateval", temp);
1644}
1645
1646// --- atf_amc.DispType2..ReadStrptrMaybe
1647// Read fields of atf_amc::DispType2 from an ascii string.
1648// The format of the string is the format of the atf_amc::DispType2's only field
1649bool atf_amc::DispType2_ReadStrptrMaybe(atf_amc::DispType2 &parent, algo::strptr in_str) {
1650 bool retval = true;
1651 retval = retval && u32_ReadStrptrMaybe(parent.intval, in_str);
1652 return retval;
1653}
1654
1655// --- atf_amc.DispType2..Print
1656// print string representation of ROW to string STR
1657// cfmt:atf_amc.DispType2.String printfmt:Raw
1658void atf_amc::DispType2_Print(atf_amc::DispType2& row, algo::cstring& str) {
1659 u32_Print(row.intval, str);
1660}
1661
1662// --- atf_amc.DispType3..ReadFieldMaybe
1663bool atf_amc::DispType3_ReadFieldMaybe(atf_amc::DispType3& parent, algo::strptr field, algo::strptr strval) {
1664 bool retval = true;
1665 atf_amc::FieldId field_id;
1666 (void)value_SetStrptrMaybe(field_id,field);
1667 switch(field_id) {
1668 case atf_amc_FieldId_intval: {
1669 retval = u32_ReadStrptrMaybe(parent.intval, strval);
1670 break;
1671 }
1672 case atf_amc_FieldId_strval: {
1673 retval = algo::Smallstr20_ReadStrptrMaybe(parent.strval, strval);
1674 break;
1675 }
1676 default: break;
1677 }
1678 if (!retval) {
1679 algo_lib::AppendErrtext("attr",field);
1680 }
1681 return retval;
1682}
1683
1684// --- atf_amc.DispType3..ReadStrptrMaybe
1685// Read fields of atf_amc::DispType3 from an ascii string.
1686// The format of the string is an ssim Tuple
1687bool atf_amc::DispType3_ReadStrptrMaybe(atf_amc::DispType3 &parent, algo::strptr in_str) {
1688 bool retval = true;
1689 retval = algo::StripTypeTag(in_str, "atf_amc.DispType3");
1690 ind_beg(algo::Attr_curs, attr, in_str) {
1691 retval = retval && DispType3_ReadFieldMaybe(parent, attr.name, attr.value);
1692 }ind_end;
1693 return retval;
1694}
1695
1696// --- atf_amc.DispType3..Print
1697// print string representation of ROW to string STR
1698// cfmt:atf_amc.DispType3.String printfmt:Tuple
1699void atf_amc::DispType3_Print(atf_amc::DispType3& row, algo::cstring& str) {
1700 algo::tempstr temp;
1701 str << "atf_amc.DispType3";
1702
1703 u32_Print(row.intval, temp);
1704 PrintAttrSpaceReset(str,"intval", temp);
1705
1706 algo::Smallstr20_Print(row.strval, temp);
1707 PrintAttrSpaceReset(str,"strval", temp);
1708}
1709
1710// --- atf_amc.FAmctest.msghdr.CopyOut
1711// Copy fields out of row
1712void atf_amc::amctest_CopyOut(atf_amc::FAmctest &row, atfdb::Amctest &out) {
1713 out.amctest = row.amctest;
1714 out.comment = row.comment;
1715}
1716
1717// --- atf_amc.FAmctest.msghdr.CopyIn
1718// Copy fields in to row
1719void atf_amc::amctest_CopyIn(atf_amc::FAmctest &row, atfdb::Amctest &in) {
1720 row.amctest = in.amctest;
1721 row.comment = in.comment;
1722}
1723
1724// --- atf_amc.FAmctest..Print
1725// print string representation of ROW to string STR
1726// cfmt:atf_amc.FAmctest.String printfmt:Tuple
1727void atf_amc::FAmctest_Print(atf_amc::FAmctest& row, algo::cstring& str) {
1728 algo::tempstr temp;
1729 str << "atf_amc.FAmctest";
1730
1731 algo::Smallstr50_Print(row.amctest, temp);
1732 PrintAttrSpaceReset(str,"amctest", temp);
1733
1734 algo::Comment_Print(row.comment, temp);
1735 PrintAttrSpaceReset(str,"comment", temp);
1736
1737 bool_Print(row.select, temp);
1738 PrintAttrSpaceReset(str,"select", temp);
1739
1740 bool_Print(row.success, temp);
1741 PrintAttrSpaceReset(str,"success", temp);
1742
1743 u64_PrintHex(u64(row.c_syscmd), temp, 8, true);
1744 PrintAttrSpaceReset(str,"c_syscmd", temp);
1745}
1746
1747// --- atf_amc.FAvl..Uninit
1748void atf_amc::FAvl_Uninit(atf_amc::FAvl& avl) {
1749 atf_amc::FAvl &row = avl; (void)row;
1750 tr_avl_Remove(row); // remove avl from index tr_avl
1751}
1752
1753// --- atf_amc.FCascdel.type.ToCstr
1754// Convert numeric value of field to one of predefined string constants.
1755// If string is found, return a static C string. Otherwise, return NULL.
1756const char* atf_amc::type_ToCstr(const atf_amc::FCascdel& cascdel) {
1757 const char *ret = NULL;
1758 switch(type_GetEnum(cascdel)) {
1759 case atf_amc_FCascdel_type_none : ret = "none"; break;
1760 case atf_amc_FCascdel_type_ptr : ret = "ptr"; break;
1761 case atf_amc_FCascdel_type_ptrary : ret = "ptrary"; break;
1762 case atf_amc_FCascdel_type_thash : ret = "thash"; break;
1763 case atf_amc_FCascdel_type_bheap : ret = "bheap"; break;
1764 case atf_amc_FCascdel_type_zdlist : ret = "zdlist"; break;
1765 }
1766 return ret;
1767}
1768
1769// --- atf_amc.FCascdel.type.Print
1770// Convert type to a string. First, attempt conversion to a known string.
1771// If no string matches, print type as a numeric value.
1772void atf_amc::type_Print(const atf_amc::FCascdel& cascdel, algo::cstring &lhs) {
1773 const char *strval = type_ToCstr(cascdel);
1774 if (strval) {
1775 lhs << strval;
1776 } else {
1777 lhs << cascdel.type;
1778 }
1779}
1780
1781// --- atf_amc.FCascdel.type.SetStrptrMaybe
1782// Convert string to field.
1783// If the string is invalid, do not modify field and return false.
1784// In case of success, return true
1785bool atf_amc::type_SetStrptrMaybe(atf_amc::FCascdel& cascdel, algo::strptr rhs) {
1786 bool ret = false;
1787 switch (elems_N(rhs)) {
1788 case 3: {
1789 switch (u64(algo::ReadLE16(rhs.elems))|(u64(rhs[2])<<16)) {
1790 case LE_STR3('p','t','r'): {
1791 type_SetEnum(cascdel,atf_amc_FCascdel_type_ptr); ret = true; break;
1792 }
1793 }
1794 break;
1795 }
1796 case 4: {
1797 switch (u64(algo::ReadLE32(rhs.elems))) {
1798 case LE_STR4('n','o','n','e'): {
1799 type_SetEnum(cascdel,atf_amc_FCascdel_type_none); ret = true; break;
1800 }
1801 }
1802 break;
1803 }
1804 case 5: {
1805 switch (u64(algo::ReadLE32(rhs.elems))|(u64(rhs[4])<<32)) {
1806 case LE_STR5('a','t','r','e','e'): {
1807 type_SetEnum(cascdel,atf_amc_FCascdel_type_atree); ret = true; break;
1808 }
1809 case LE_STR5('b','h','e','a','p'): {
1810 type_SetEnum(cascdel,atf_amc_FCascdel_type_bheap); ret = true; break;
1811 }
1812 case LE_STR5('t','h','a','s','h'): {
1813 type_SetEnum(cascdel,atf_amc_FCascdel_type_thash); ret = true; break;
1814 }
1815 }
1816 break;
1817 }
1818 case 6: {
1819 switch (u64(algo::ReadLE32(rhs.elems))|(u64(algo::ReadLE16(rhs.elems+4))<<32)) {
1820 case LE_STR6('p','t','r','a','r','y'): {
1821 type_SetEnum(cascdel,atf_amc_FCascdel_type_ptrary); ret = true; break;
1822 }
1823 case LE_STR6('z','d','l','i','s','t'): {
1824 type_SetEnum(cascdel,atf_amc_FCascdel_type_zdlist); ret = true; break;
1825 }
1826 }
1827 break;
1828 }
1829 }
1830 return ret;
1831}
1832
1833// --- atf_amc.FCascdel.type.SetStrptr
1834// Convert string to field.
1835// If the string is invalid, set numeric value to DFLT
1836void atf_amc::type_SetStrptr(atf_amc::FCascdel& cascdel, algo::strptr rhs, atf_amc_FCascdel_type_Enum dflt) {
1837 if (!type_SetStrptrMaybe(cascdel,rhs)) type_SetEnum(cascdel,dflt);
1838}
1839
1840// --- atf_amc.FCascdel.child_ptr.Cascdel
1841// Delete referred-to items.
1842// Deleted pointed-to item.
1843void atf_amc::child_ptr_Cascdel(atf_amc::FCascdel& cascdel) {
1844 atf_amc::FCascdel *ptr = cascdel.child_ptr;
1845 if (ptr) {
1846 cascdel_Delete(*ptr);
1847 cascdel.child_ptr = NULL;
1848 }
1849}
1850
1851// --- atf_amc.FCascdel.c_child_ptrary.Cascdel
1852// Delete all elements pointed to by the index.
1853void atf_amc::c_child_ptrary_Cascdel(atf_amc::FCascdel& cascdel) {
1854 // Clear c_child_ptrary_n so that calls to atf_amc.FCascdel.c_child_ptrary.Remove do not have to scan
1855 // the array for pointers or shift anything.
1856 // This is somewhat of a hack.
1857 i32 n = cascdel.c_child_ptrary_n;
1858 cascdel.c_child_ptrary_n = 0;
1859 for (i32 i = n - 1; i >= 0; i--) {
1860 atf_amc::FCascdel &row = *cascdel.c_child_ptrary_elems[i];
1861 row.cascdel_c_child_ptrary_in_ary = false;
1862 cascdel_Delete(row);
1863 }
1864}
1865
1866// --- atf_amc.FCascdel.c_child_ptrary.Insert
1867// Insert pointer to row into array. Row must not already be in array.
1868// If pointer is already in the array, it may be inserted twice.
1869void atf_amc::c_child_ptrary_Insert(atf_amc::FCascdel& cascdel, atf_amc::FCascdel& row) {
1870 if (bool_Update(row.cascdel_c_child_ptrary_in_ary,true)) {
1871 // reserve space
1872 c_child_ptrary_Reserve(cascdel, 1);
1873 u32 n = cascdel.c_child_ptrary_n;
1874 u32 at = n;
1875 atf_amc::FCascdel* *elems = cascdel.c_child_ptrary_elems;
1876 elems[at] = &row;
1877 cascdel.c_child_ptrary_n = n+1;
1878
1879 }
1880}
1881
1882// --- atf_amc.FCascdel.c_child_ptrary.InsertMaybe
1883// Insert pointer to row in array.
1884// If row is already in the array, do nothing.
1885// Return value: whether element was inserted into array.
1886bool atf_amc::c_child_ptrary_InsertMaybe(atf_amc::FCascdel& cascdel, atf_amc::FCascdel& row) {
1887 bool retval = !row.cascdel_c_child_ptrary_in_ary;
1888 c_child_ptrary_Insert(cascdel,row); // check is performed in _Insert again
1889 return retval;
1890}
1891
1892// --- atf_amc.FCascdel.c_child_ptrary.Remove
1893// Find element using linear scan. If element is in array, remove, otherwise do nothing
1894void atf_amc::c_child_ptrary_Remove(atf_amc::FCascdel& cascdel, atf_amc::FCascdel& row) {
1895 if (bool_Update(row.cascdel_c_child_ptrary_in_ary,false)) {
1896 int lim = cascdel.c_child_ptrary_n;
1897 atf_amc::FCascdel* *elems = cascdel.c_child_ptrary_elems;
1898 // search backward, so that most recently added element is found first.
1899 // if found, shift array.
1900 for (int i = lim-1; i>=0; i--) {
1901 atf_amc::FCascdel* elem = elems[i]; // fetch element
1902 if (elem == &row) {
1903 int j = i + 1;
1904 size_t nbytes = sizeof(atf_amc::FCascdel*) * (lim - j);
1905 memmove(elems + i, elems + j, nbytes);
1906 cascdel.c_child_ptrary_n = lim - 1;
1907 break;
1908 }
1909 }
1910 }
1911}
1912
1913// --- atf_amc.FCascdel.c_child_ptrary.Reserve
1914// Reserve space in index for N more elements;
1915void atf_amc::c_child_ptrary_Reserve(atf_amc::FCascdel& cascdel, u32 n) {
1916 u32 old_max = cascdel.c_child_ptrary_max;
1917 if (UNLIKELY(cascdel.c_child_ptrary_n + n > old_max)) {
1918 u32 new_max = u32_Max(4, old_max * 2);
1919 u32 old_size = old_max * sizeof(atf_amc::FCascdel*);
1920 u32 new_size = new_max * sizeof(atf_amc::FCascdel*);
1921 void *new_mem = algo_lib::malloc_ReallocMem(cascdel.c_child_ptrary_elems, old_size, new_size);
1922 if (UNLIKELY(!new_mem)) {
1923 FatalErrorExit("atf_amc.out_of_memory field:atf_amc.FCascdel.c_child_ptrary");
1924 }
1925 cascdel.c_child_ptrary_elems = (atf_amc::FCascdel**)new_mem;
1926 cascdel.c_child_ptrary_max = new_max;
1927 }
1928}
1929
1930// --- atf_amc.FCascdel.ind_child_thash.Cascdel
1931// Delete all rows reachable through the hash index
1932void atf_amc::ind_child_thash_Cascdel(atf_amc::FCascdel& cascdel) {
1933 if (cascdel.ind_child_thash_n) {
1934 for (int i = 0; i < cascdel.ind_child_thash_buckets_n; i++) {
1935 atf_amc::FCascdel *elem = cascdel.ind_child_thash_buckets_elems[i];
1936 while (elem) {
1937 atf_amc::FCascdel *next = elem->ind_child_thash_next;
1938 cascdel_Delete(*elem);
1939 elem = next;
1940 }
1941 }
1942 }
1943}
1944
1945// --- atf_amc.FCascdel.ind_child_thash.Find
1946// Find row by key. Return NULL if not found.
1947atf_amc::FCascdel* atf_amc::ind_child_thash_Find(atf_amc::FCascdel& cascdel, u32 key) {
1948 u32 index = ::u32_Hash(0, key) & (cascdel.ind_child_thash_buckets_n - 1);
1949 atf_amc::FCascdel* *e = &cascdel.ind_child_thash_buckets_elems[index];
1950 atf_amc::FCascdel* ret=NULL;
1951 do {
1952 ret = *e;
1953 bool done = !ret || (*ret).key == key;
1954 if (done) break;
1955 e = &ret->ind_child_thash_next;
1956 } while (true);
1957 return ret;
1958}
1959
1960// --- atf_amc.FCascdel.ind_child_thash.InsertMaybe
1961// Insert row into hash table. Return true if row is reachable through the hash after the function completes.
1962bool atf_amc::ind_child_thash_InsertMaybe(atf_amc::FCascdel& cascdel, atf_amc::FCascdel& row) {
1963 ind_child_thash_Reserve(cascdel, 1);
1964 bool retval = true; // if already in hash, InsertMaybe returns true
1965 if (LIKELY(row.ind_child_thash_next == (atf_amc::FCascdel*)-1)) {// check if in hash already
1966 u32 index = ::u32_Hash(0, row.key) & (cascdel.ind_child_thash_buckets_n - 1);
1967 atf_amc::FCascdel* *prev = &cascdel.ind_child_thash_buckets_elems[index];
1968 do {
1969 atf_amc::FCascdel* ret = *prev;
1970 if (!ret) { // exit condition 1: reached the end of the list
1971 break;
1972 }
1973 if ((*ret).key == row.key) { // exit condition 2: found matching key
1974 retval = false;
1975 break;
1976 }
1977 prev = &ret->ind_child_thash_next;
1978 } while (true);
1979 if (retval) {
1980 row.ind_child_thash_next = *prev;
1981 cascdel.ind_child_thash_n++;
1982 *prev = &row;
1983 }
1984 }
1985 return retval;
1986}
1987
1988// --- atf_amc.FCascdel.ind_child_thash.Remove
1989// Remove reference to element from hash index. If element is not in hash, do nothing
1990void atf_amc::ind_child_thash_Remove(atf_amc::FCascdel& cascdel, atf_amc::FCascdel& row) {
1991 if (LIKELY(row.ind_child_thash_next != (atf_amc::FCascdel*)-1)) {// check if in hash already
1992 u32 index = ::u32_Hash(0, row.key) & (cascdel.ind_child_thash_buckets_n - 1);
1993 atf_amc::FCascdel* *prev = &cascdel.ind_child_thash_buckets_elems[index]; // addr of pointer to current element
1994 while (atf_amc::FCascdel *next = *prev) { // scan the collision chain for our element
1995 if (next == &row) { // found it?
1996 *prev = next->ind_child_thash_next; // unlink (singly linked list)
1997 cascdel.ind_child_thash_n--;
1998 row.ind_child_thash_next = (atf_amc::FCascdel*)-1;// not-in-hash
1999 break;
2000 }
2001 prev = &next->ind_child_thash_next;
2002 }
2003 }
2004}
2005
2006// --- atf_amc.FCascdel.ind_child_thash.Reserve
2007// Reserve enough room in the hash for N more elements. Return success code.
2008void atf_amc::ind_child_thash_Reserve(atf_amc::FCascdel& cascdel, int n) {
2009 u32 old_nbuckets = cascdel.ind_child_thash_buckets_n;
2010 u32 new_nelems = cascdel.ind_child_thash_n + n;
2011 // # of elements has to be roughly equal to the number of buckets
2012 if (new_nelems > old_nbuckets) {
2013 int new_nbuckets = i32_Max(algo::BumpToPow2(new_nelems), u32(4));
2014 u32 old_size = old_nbuckets * sizeof(atf_amc::FCascdel*);
2015 u32 new_size = new_nbuckets * sizeof(atf_amc::FCascdel*);
2016 // allocate new array. we don't use Realloc since copying is not needed and factor of 2 probably
2017 // means new memory will have to be allocated anyway
2018 atf_amc::FCascdel* *new_buckets = (atf_amc::FCascdel**)algo_lib::malloc_AllocMem(new_size);
2019 if (UNLIKELY(!new_buckets)) {
2020 FatalErrorExit("atf_amc.out_of_memory field:atf_amc.FCascdel.ind_child_thash");
2021 }
2022 memset(new_buckets, 0, new_size); // clear pointers
2023 // rehash all entries
2024 for (int i = 0; i < cascdel.ind_child_thash_buckets_n; i++) {
2025 atf_amc::FCascdel* elem = cascdel.ind_child_thash_buckets_elems[i];
2026 while (elem) {
2027 atf_amc::FCascdel &row = *elem;
2028 atf_amc::FCascdel* next = row.ind_child_thash_next;
2029 u32 index = ::u32_Hash(0, row.key) & (new_nbuckets-1);
2030 row.ind_child_thash_next = new_buckets[index];
2031 new_buckets[index] = &row;
2032 elem = next;
2033 }
2034 }
2035 // free old array
2036 algo_lib::malloc_FreeMem(cascdel.ind_child_thash_buckets_elems, old_size);
2037 cascdel.ind_child_thash_buckets_elems = new_buckets;
2038 cascdel.ind_child_thash_buckets_n = new_nbuckets;
2039 }
2040}
2041
2042// --- atf_amc.FCascdel.bh_child_bheap.Cascdel
2043// Delete referred-to items.
2044// Delete all elements referenced by the heap.
2045void atf_amc::bh_child_bheap_Cascdel(atf_amc::FCascdel& cascdel) {
2046 i32 n = cascdel.bh_child_bheap_n;
2047 while (n > 0) {
2048 n--;
2049 atf_amc::FCascdel &elem = *cascdel.bh_child_bheap_elems[n]; // pick cheapest element to remove
2050 elem.bh_child_bheap_idx = -1; // mark not-in-heap
2051 cascdel.bh_child_bheap_n = n;
2052 cascdel_Delete(elem);
2053 }
2054}
2055
2056// --- atf_amc.FCascdel.bh_child_bheap.Dealloc
2057// Remove all elements from heap and free memory used by the array.
2058void atf_amc::bh_child_bheap_Dealloc(atf_amc::FCascdel& cascdel) {
2059 bh_child_bheap_RemoveAll(cascdel);
2060 algo_lib::malloc_FreeMem(cascdel.bh_child_bheap_elems, sizeof(atf_amc::FCascdel*)*cascdel.bh_child_bheap_max);
2061 cascdel.bh_child_bheap_max = 0;
2062 cascdel.bh_child_bheap_elems = NULL;
2063}
2064
2065// --- atf_amc.FCascdel.bh_child_bheap.Downheap
2066// Find new location for ROW starting at IDX
2067// NOTE: Rest of heap is rearranged, but pointer to ROW is NOT stored in array.
2068static int atf_amc::bh_child_bheap_Downheap(atf_amc::FCascdel& cascdel, atf_amc::FCascdel& row, int idx) {
2069 atf_amc::FCascdel* *elems = cascdel.bh_child_bheap_elems;
2070 int n = cascdel.bh_child_bheap_n;
2071 int child = idx*2+1;
2072 while (child < n) {
2073 atf_amc::FCascdel* p = elems[child]; // left child
2074 int rchild = child+1;
2075 if (rchild < n) {
2076 atf_amc::FCascdel* q = elems[rchild]; // right child
2077 if (bh_child_bheap_ElemLt(cascdel, *q,*p)) {
2078 child = rchild;
2079 p = q;
2080 }
2081 }
2082 if (!bh_child_bheap_ElemLt(cascdel, *p,row)) {
2083 break;
2084 }
2085 p->bh_child_bheap_idx = idx;
2086 elems[idx] = p;
2087 idx = child;
2088 child = idx*2+1;
2089 }
2090 return idx;
2091}
2092
2093// --- atf_amc.FCascdel.bh_child_bheap.Insert
2094// Insert row. Row must not already be in index. If row is already in index, do nothing.
2095void atf_amc::bh_child_bheap_Insert(atf_amc::FCascdel& cascdel, atf_amc::FCascdel& row) {
2096 if (LIKELY(row.bh_child_bheap_idx == -1)) {
2097 bh_child_bheap_Reserve(cascdel, 1);
2098 int n = cascdel.bh_child_bheap_n;
2099 cascdel.bh_child_bheap_n = n + 1;
2100 int new_idx = bh_child_bheap_Upheap(cascdel, row, n);
2101 row.bh_child_bheap_idx = new_idx;
2102 cascdel.bh_child_bheap_elems[new_idx] = &row;
2103 }
2104}
2105
2106// --- atf_amc.FCascdel.bh_child_bheap.Reheap
2107// If row is in heap, update its position. If row is not in heap, insert it.
2108// Return new position of item in the heap (0=top)
2109i32 atf_amc::bh_child_bheap_Reheap(atf_amc::FCascdel& cascdel, atf_amc::FCascdel& row) {
2110 int old_idx = row.bh_child_bheap_idx;
2111 bool isnew = old_idx == -1;
2112 if (isnew) {
2113 bh_child_bheap_Reserve(cascdel, 1);
2114 old_idx = cascdel.bh_child_bheap_n++;
2115 }
2116 int new_idx = bh_child_bheap_Upheap(cascdel, row, old_idx);
2117 if (!isnew && new_idx == old_idx) {
2118 new_idx = bh_child_bheap_Downheap(cascdel, row, old_idx);
2119 }
2120 row.bh_child_bheap_idx = new_idx;
2121 cascdel.bh_child_bheap_elems[new_idx] = &row;
2122 return new_idx;
2123}
2124
2125// --- atf_amc.FCascdel.bh_child_bheap.ReheapFirst
2126// Key of first element in the heap changed. Move it.
2127// This function does not check the insert condition.
2128// Return new position of item in the heap (0=top).
2129// Heap must be non-empty or behavior is undefined.
2130i32 atf_amc::bh_child_bheap_ReheapFirst(atf_amc::FCascdel& cascdel) {
2131 atf_amc::FCascdel &row = *cascdel.bh_child_bheap_elems[0];
2132 i32 new_idx = bh_child_bheap_Downheap(cascdel, row, 0);
2133 row.bh_child_bheap_idx = new_idx;
2134 cascdel.bh_child_bheap_elems[new_idx] = &row;
2135 return new_idx;
2136}
2137
2138// --- atf_amc.FCascdel.bh_child_bheap.Remove
2139// Remove element from index. If element is not in index, do nothing.
2140void atf_amc::bh_child_bheap_Remove(atf_amc::FCascdel& cascdel, atf_amc::FCascdel& row) {
2141 if (bh_child_bheap_InBheapQ(row)) {
2142 int old_idx = row.bh_child_bheap_idx;
2143 if (cascdel.bh_child_bheap_elems[old_idx] == &row) { // sanity check: heap points back to row
2144 row.bh_child_bheap_idx = -1; // mark not in heap
2145 i32 n = cascdel.bh_child_bheap_n - 1; // index of last element in heap
2146 cascdel.bh_child_bheap_n = n; // decrease count
2147 if (old_idx != n) {
2148 atf_amc::FCascdel *elem = cascdel.bh_child_bheap_elems[n];
2149 int new_idx = bh_child_bheap_Upheap(cascdel, *elem, old_idx);
2150 if (new_idx == old_idx) {
2151 new_idx = bh_child_bheap_Downheap(cascdel, *elem, old_idx);
2152 }
2153 elem->bh_child_bheap_idx = new_idx;
2154 cascdel.bh_child_bheap_elems[new_idx] = elem;
2155 }
2156 }
2157 }
2158}
2159
2160// --- atf_amc.FCascdel.bh_child_bheap.RemoveAll
2161// Remove all elements from binary heap
2162void atf_amc::bh_child_bheap_RemoveAll(atf_amc::FCascdel& cascdel) {
2163 int n = cascdel.bh_child_bheap_n;
2164 for (int i = n - 1; i>=0; i--) {
2165 cascdel.bh_child_bheap_elems[i]->bh_child_bheap_idx = -1; // mark not-in-heap
2166 }
2167 cascdel.bh_child_bheap_n = 0;
2168}
2169
2170// --- atf_amc.FCascdel.bh_child_bheap.RemoveFirst
2171// If index is empty, return NULL. Otherwise remove and return first key in index.
2172// Call 'head changed' trigger.
2173atf_amc::FCascdel* atf_amc::bh_child_bheap_RemoveFirst(atf_amc::FCascdel& cascdel) {
2174 atf_amc::FCascdel *row = NULL;
2175 if (cascdel.bh_child_bheap_n > 0) {
2176 row = cascdel.bh_child_bheap_elems[0];
2177 row->bh_child_bheap_idx = -1; // mark not in heap
2178 i32 n = cascdel.bh_child_bheap_n - 1; // index of last element in heap
2179 cascdel.bh_child_bheap_n = n; // decrease count
2180 if (n) {
2181 atf_amc::FCascdel &elem = *cascdel.bh_child_bheap_elems[n];
2182 int new_idx = bh_child_bheap_Downheap(cascdel, elem, 0);
2183 elem.bh_child_bheap_idx = new_idx;
2184 cascdel.bh_child_bheap_elems[new_idx] = &elem;
2185 }
2186 }
2187 return row;
2188}
2189
2190// --- atf_amc.FCascdel.bh_child_bheap.Reserve
2191// Reserve space in index for N more elements
2192void atf_amc::bh_child_bheap_Reserve(atf_amc::FCascdel& cascdel, int n) {
2193 i32 old_max = cascdel.bh_child_bheap_max;
2194 if (UNLIKELY(cascdel.bh_child_bheap_n + n > old_max)) {
2195 u32 new_max = u32_Max(4, old_max * 2);
2196 u32 old_size = old_max * sizeof(atf_amc::FCascdel*);
2197 u32 new_size = new_max * sizeof(atf_amc::FCascdel*);
2198 void *new_mem = algo_lib::malloc_ReallocMem(cascdel.bh_child_bheap_elems, old_size, new_size);
2199 if (UNLIKELY(!new_mem)) {
2200 FatalErrorExit("atf_amc.out_of_memory field:atf_amc.FCascdel.bh_child_bheap");
2201 }
2202 cascdel.bh_child_bheap_elems = (atf_amc::FCascdel**)new_mem;
2203 cascdel.bh_child_bheap_max = new_max;
2204 }
2205}
2206
2207// --- atf_amc.FCascdel.bh_child_bheap.Set
2208// Set row key to new value.
2209// Update heap membership based on insert condition [row.p_parent != &row && row.type==atf_amc_FCascdel_type_bheap]
2210void atf_amc::key_Set(atf_amc::FCascdel& cascdel, atf_amc::FCascdel &row, u32 new_key) {
2211 row.key = new_key;
2212 bool ins = row.p_parent != &row && row.type==atf_amc_FCascdel_type_bheap; // user-defined insert condition (xref)
2213 if (ins) {
2214 bh_child_bheap_Reheap(cascdel, row);
2215 } else {
2216 bh_child_bheap_Remove(cascdel, row);
2217 }
2218}
2219
2220// --- atf_amc.FCascdel.bh_child_bheap.SetIfBetter
2221// Set row key to new value. If row not in heap, the key is set to new value
2222// Otherwise, the key is changed only if the new key is better than the old.
2223// Update heap membership based on insert condition [row.p_parent != &row && row.type==atf_amc_FCascdel_type_bheap]
2224void atf_amc::key_SetIfBetter(atf_amc::FCascdel& cascdel, atf_amc::FCascdel &row, u32 new_key) {
2225 bool better = true;
2226 if (bh_child_bheap_InBheapQ(row)) {
2227 better = !bh_child_bheap_ElemLtval(cascdel, row,new_key); // this is really Not Worse, not Better
2228 }
2229 if (better) {
2230 key_Set(cascdel, row, new_key);
2231 }
2232}
2233
2234// --- atf_amc.FCascdel.bh_child_bheap.Upheap
2235// Find and return index of new location for element ROW in the heap, starting at index IDX.
2236// Move any elements along the way but do not modify ROW.
2237static int atf_amc::bh_child_bheap_Upheap(atf_amc::FCascdel& cascdel, atf_amc::FCascdel& row, int idx) {
2238 atf_amc::FCascdel* *elems = cascdel.bh_child_bheap_elems;
2239 while (idx>0) {
2240 int j = (idx-1)/2;
2241 atf_amc::FCascdel* p = elems[j];
2242 if (!bh_child_bheap_ElemLt(cascdel, row, *p)) {
2243 break;
2244 }
2245 p->bh_child_bheap_idx = idx;
2246 elems[idx] = p;
2247 idx = j;
2248 }
2249 return idx;
2250}
2251
2252// --- atf_amc.FCascdel.bh_child_bheap.ElemLt
2253inline static bool atf_amc::bh_child_bheap_ElemLt(atf_amc::FCascdel& cascdel, atf_amc::FCascdel &a, atf_amc::FCascdel &b) {
2254 (void)cascdel;
2255 return a.key < b.key;
2256}
2257
2258// --- atf_amc.FCascdel.bh_child_bheap.ElemLtval
2259inline static bool atf_amc::bh_child_bheap_ElemLtval(atf_amc::FCascdel& cascdel, atf_amc::FCascdel &a, const u32 &b) {
2260 (void)cascdel;
2261 return a.key < (u32&)b;
2262}
2263
2264// --- atf_amc.FCascdel.zd_childlist.Cascdel
2265// Delete all elements in the linked list.
2266void atf_amc::zd_childlist_Cascdel(atf_amc::FCascdel& cascdel) {
2267 while (atf_amc::FCascdel *zd_childlist_first = zd_childlist_First(cascdel)) {
2268 cascdel_Delete(*zd_childlist_first);
2269 }
2270}
2271
2272// --- atf_amc.FCascdel.zd_childlist.Insert
2273// Insert row into linked list. If row is already in linked list, do nothing.
2274void atf_amc::zd_childlist_Insert(atf_amc::FCascdel& cascdel, atf_amc::FCascdel& row) {
2275 if (!zd_childlist_InLlistQ(row)) {
2276 atf_amc::FCascdel* old_tail = cascdel.zd_childlist_tail;
2277 row.zd_childlist_next = NULL;
2278 row.zd_childlist_prev = old_tail;
2279 cascdel.zd_childlist_tail = &row;
2280 atf_amc::FCascdel **new_row_a = &old_tail->zd_childlist_next;
2281 atf_amc::FCascdel **new_row_b = &cascdel.zd_childlist_head;
2282 atf_amc::FCascdel **new_row = old_tail ? new_row_a : new_row_b;
2283 *new_row = &row;
2284 cascdel.zd_childlist_n++;
2285 }
2286}
2287
2288// --- atf_amc.FCascdel.zd_childlist.Remove
2289// Remove element from index. If element is not in index, do nothing.
2290void atf_amc::zd_childlist_Remove(atf_amc::FCascdel& cascdel, atf_amc::FCascdel& row) {
2291 if (zd_childlist_InLlistQ(row)) {
2292 atf_amc::FCascdel* old_head = cascdel.zd_childlist_head;
2293 (void)old_head; // in case it's not used
2294 atf_amc::FCascdel* prev = row.zd_childlist_prev;
2295 atf_amc::FCascdel* next = row.zd_childlist_next;
2296 // if element is first, adjust list head; otherwise, adjust previous element's next
2297 atf_amc::FCascdel **new_next_a = &prev->zd_childlist_next;
2298 atf_amc::FCascdel **new_next_b = &cascdel.zd_childlist_head;
2299 atf_amc::FCascdel **new_next = prev ? new_next_a : new_next_b;
2300 *new_next = next;
2301 // if element is last, adjust list tail; otherwise, adjust next element's prev
2302 atf_amc::FCascdel **new_prev_a = &next->zd_childlist_prev;
2303 atf_amc::FCascdel **new_prev_b = &cascdel.zd_childlist_tail;
2304 atf_amc::FCascdel **new_prev = next ? new_prev_a : new_prev_b;
2305 *new_prev = prev;
2306 cascdel.zd_childlist_n--;
2307 row.zd_childlist_next=(atf_amc::FCascdel*)-1; // not-in-list
2308 }
2309}
2310
2311// --- atf_amc.FCascdel.zd_childlist.RemoveAll
2312// Empty the index. (The rows are not deleted)
2313void atf_amc::zd_childlist_RemoveAll(atf_amc::FCascdel& cascdel) {
2314 atf_amc::FCascdel* row = cascdel.zd_childlist_head;
2315 cascdel.zd_childlist_head = NULL;
2316 cascdel.zd_childlist_tail = NULL;
2317 cascdel.zd_childlist_n = 0;
2318 while (row) {
2319 atf_amc::FCascdel* row_next = row->zd_childlist_next;
2320 row->zd_childlist_next = (atf_amc::FCascdel*)-1;
2321 row->zd_childlist_prev = NULL;
2322 row = row_next;
2323 }
2324}
2325
2326// --- atf_amc.FCascdel.zd_childlist.RemoveFirst
2327// If linked list is empty, return NULL. Otherwise unlink and return pointer to first element.
2328atf_amc::FCascdel* atf_amc::zd_childlist_RemoveFirst(atf_amc::FCascdel& cascdel) {
2329 atf_amc::FCascdel *row = NULL;
2330 row = cascdel.zd_childlist_head;
2331 if (row) {
2332 atf_amc::FCascdel *next = row->zd_childlist_next;
2333 cascdel.zd_childlist_head = next;
2334 atf_amc::FCascdel **new_end_a = &next->zd_childlist_prev;
2335 atf_amc::FCascdel **new_end_b = &cascdel.zd_childlist_tail;
2336 atf_amc::FCascdel **new_end = next ? new_end_a : new_end_b;
2337 *new_end = NULL;
2338 cascdel.zd_childlist_n--;
2339 row->zd_childlist_next = (atf_amc::FCascdel*)-1; // mark as not-in-list
2340 }
2341 return row;
2342}
2343
2344// --- atf_amc.FCascdel.tr_child_atree.Cascdel
2345// Delete all elements in the tree.
2346void atf_amc::tr_child_atree_Cascdel(atf_amc::FCascdel& cascdel) {
2347 tr_child_atree_RemoveAllImpl(cascdel, cascdel.tr_child_atree_root, true);
2348 cascdel.tr_child_atree_root = NULL;
2349 cascdel.tr_child_atree_n = 0;
2350}
2351
2352// --- atf_amc.FCascdel.tr_child_atree.FirstImpl
2353atf_amc::FCascdel* atf_amc::tr_child_atree_FirstImpl(atf_amc::FCascdel* root) {
2354 atf_amc::FCascdel *result = root;
2355 while(result != NULL && result->tr_child_atree_left != NULL){
2356 result = result->tr_child_atree_left;
2357 }
2358 return result;
2359}
2360
2361// --- atf_amc.FCascdel.tr_child_atree.First
2362// Return pointer to the first(smallest) element in the tree
2363atf_amc::FCascdel* atf_amc::tr_child_atree_First(atf_amc::FCascdel& cascdel) {
2364 return tr_child_atree_FirstImpl(cascdel.tr_child_atree_root);
2365}
2366
2367// --- atf_amc.FCascdel.tr_child_atree.InsertImpl
2368// Insert row into the tree. If row is already in the tree, do nothing.
2369void atf_amc::tr_child_atree_InsertImpl(atf_amc::FCascdel& cascdel, atf_amc::FCascdel* parent, atf_amc::FCascdel& row) {
2370 bool left = false;
2371 while(parent != NULL){
2372 left = tr_child_atree_ElemLt(cascdel, row, *parent);
2373 atf_amc::FCascdel* side = left ? parent->tr_child_atree_left : parent->tr_child_atree_right;
2374 if(side == NULL){
2375 break;
2376 }
2377 parent = side;
2378 }
2379 tr_child_atree_Connect(parent, &row, left);
2380}
2381
2382// --- atf_amc.FCascdel.tr_child_atree.Insert
2383// Insert row into the tree. If row is already in the tree, do nothing.
2384void atf_amc::tr_child_atree_Insert(atf_amc::FCascdel& cascdel, atf_amc::FCascdel& row) {
2385 if(!tr_child_atree_InTreeQ(row)){
2386 cascdel.tr_child_atree_n++;
2387 tr_child_atree_InsertImpl(cascdel, cascdel.tr_child_atree_root, row);
2388 cascdel.tr_child_atree_root = tr_child_atree_Propagate(row);
2389 }
2390}
2391
2392// --- atf_amc.FCascdel.tr_child_atree.Remove
2393// Remove element from index. If element is not in index, do nothing.
2394void atf_amc::tr_child_atree_Remove(atf_amc::FCascdel& cascdel, atf_amc::FCascdel& row) {
2395 if(!tr_child_atree_InTreeQ(row)){
2396 return;
2397 }
2398 atf_amc::FCascdel* next = NULL;
2399 if(row.tr_child_atree_depth > 1){
2400 next = tr_child_atree_Balance(row) < 0 ? tr_child_atree_FirstImpl(row.tr_child_atree_right) : tr_child_atree_LastImpl(row.tr_child_atree_left);
2401 atf_amc::FCascdel* leaf = tr_child_atree_TallerChild(*next);
2402 if(leaf){
2403 tr_child_atree_Turn(*leaf, *next);
2404 }
2405 }
2406 atf_amc::FCascdel* root = row.tr_child_atree_up;
2407 atf_amc::FCascdel* prop = root;//propagate point
2408 if(next){
2409 prop = next->tr_child_atree_up == &row ? next : next->tr_child_atree_up;
2410 tr_child_atree_Disconnect(*next);
2411 tr_child_atree_Connect(next, row.tr_child_atree_left, true);
2412 tr_child_atree_Connect(next, row.tr_child_atree_right, false);
2413 }
2414 bool dir = root && root->tr_child_atree_left == &row;
2415 tr_child_atree_Connect(root, next, dir);
2416 cascdel.tr_child_atree_root = prop ? tr_child_atree_Propagate(*prop) : NULL;
2417 row.tr_child_atree_depth = 0;
2418 row.tr_child_atree_left = NULL;
2419 row.tr_child_atree_right = NULL;
2420 row.tr_child_atree_up = (atf_amc::FCascdel*)-1;
2421 cascdel.tr_child_atree_n--;
2422}
2423
2424// --- atf_amc.FCascdel.tr_child_atree.RemoveFirst
2425// If the tree is empty, return NULL. Otherwise unlink and return pointer to first element.
2426void atf_amc::tr_child_atree_RemoveFirst(atf_amc::FCascdel& cascdel) {
2427 if(!tr_child_atree_EmptyQ(cascdel)){
2428 tr_child_atree_Remove(cascdel, *tr_child_atree_First(cascdel));
2429 }
2430}
2431
2432// --- atf_amc.FCascdel.tr_child_atree.Balance
2433i32 atf_amc::tr_child_atree_Balance(atf_amc::FCascdel& row) {
2434 i32 left = row.tr_child_atree_left ? row.tr_child_atree_left->tr_child_atree_depth : 0;
2435 i32 right = row.tr_child_atree_right ? row.tr_child_atree_right->tr_child_atree_depth : 0;
2436 return left - right;
2437}
2438
2439// --- atf_amc.FCascdel.tr_child_atree.Propagate
2440// Recalculate depth and keep rebalancing if needed
2441atf_amc::FCascdel* atf_amc::tr_child_atree_Propagate(atf_amc::FCascdel& pnode) {
2442 atf_amc::FCascdel *root = &pnode;
2443 atf_amc::FCascdel* node = &pnode;
2444 while(node != NULL){
2445 tr_child_atree_updateDepth(*node);
2446 tr_child_atree_Rebalance(*node);
2447 root = node;
2448 node = node->tr_child_atree_up;
2449 }
2450 return root;
2451}
2452
2453// --- atf_amc.FCascdel.tr_child_atree.TallerChild
2454// Returns the child that has greater height.
2455inline static atf_amc::FCascdel* atf_amc::tr_child_atree_TallerChild(atf_amc::FCascdel& node) {
2456 return tr_child_atree_Balance(node) < 0 ? node.tr_child_atree_right : node.tr_child_atree_left;
2457}
2458
2459// --- atf_amc.FCascdel.tr_child_atree.Disconnect
2460// Disconnects the subtree(branch) from the parent
2461static void atf_amc::tr_child_atree_Disconnect(atf_amc::FCascdel& node) {
2462 atf_amc::FCascdel* parent = node.tr_child_atree_up;
2463 if(parent != NULL){
2464 bool left = parent->tr_child_atree_left == &node;
2465 (left ? parent->tr_child_atree_left : parent->tr_child_atree_right) = NULL;
2466 }
2467 node.tr_child_atree_up = NULL;
2468}
2469
2470// --- atf_amc.FCascdel.tr_child_atree.Rebalance
2471// Rebalances the node if needed.
2472void atf_amc::tr_child_atree_Rebalance(atf_amc::FCascdel& node) {
2473 if (algo::Abs(tr_child_atree_Balance(node)) > 1){
2474 atf_amc::FCascdel* deep1 = tr_child_atree_TallerChild(node);
2475 atf_amc::FCascdel* deep2 = tr_child_atree_TallerChild(*deep1);
2476 bool turn = tr_child_atree_Balance(*deep1)!=0 && (node.tr_child_atree_left == deep1) != (deep1->tr_child_atree_left == deep2);
2477 if(turn){
2478 tr_child_atree_Turn(*deep2, *deep1);
2479 algo::TSwap(deep1, deep2);
2480 }
2481 tr_child_atree_Turn(*deep1, node);
2482 tr_child_atree_updateDepth(node);
2483 tr_child_atree_updateDepth(*deep2);
2484 tr_child_atree_updateDepth(*deep1);
2485 }
2486}
2487
2488// --- atf_amc.FCascdel.tr_child_atree.Next
2489atf_amc::FCascdel* atf_amc::tr_child_atree_Next(atf_amc::FCascdel& node) {
2490 atf_amc::FCascdel *result = &node;
2491 if(result->tr_child_atree_right == NULL){
2492 while(result->tr_child_atree_up != NULL && result->tr_child_atree_up->tr_child_atree_right == result){
2493 result = result->tr_child_atree_up;
2494 }
2495 result = result->tr_child_atree_up;
2496 }else{
2497 result = tr_child_atree_FirstImpl(result->tr_child_atree_right);
2498 }
2499 return result;
2500}
2501
2502// --- atf_amc.FCascdel.tr_child_atree.Prev
2503atf_amc::FCascdel* atf_amc::tr_child_atree_Prev(atf_amc::FCascdel& node) {
2504 atf_amc::FCascdel *result = &node;
2505 if(result->tr_child_atree_left == NULL){
2506 while(result->tr_child_atree_up != NULL && result->tr_child_atree_up->tr_child_atree_left == result){
2507 result = result->tr_child_atree_up;
2508 }
2509 result = result->tr_child_atree_up;
2510 }else{
2511 result = tr_child_atree_LastImpl(result->tr_child_atree_left);
2512 }
2513 return result;
2514}
2515
2516// --- atf_amc.FCascdel.tr_child_atree.LastImpl
2517atf_amc::FCascdel* atf_amc::tr_child_atree_LastImpl(atf_amc::FCascdel* root) {
2518 atf_amc::FCascdel *result = root;
2519 while(result != NULL && result->tr_child_atree_right != NULL){
2520 result = result->tr_child_atree_right;
2521 }
2522 return result;
2523}
2524
2525// --- atf_amc.FCascdel.tr_child_atree.Last
2526// Return pointer to the last(largest) element in tree
2527atf_amc::FCascdel* atf_amc::tr_child_atree_Last(atf_amc::FCascdel& cascdel) {
2528 return tr_child_atree_LastImpl(cascdel.tr_child_atree_root);
2529}
2530
2531// --- atf_amc.FCascdel.tr_child_atree.ElemLt
2532inline static bool atf_amc::tr_child_atree_ElemLt(atf_amc::FCascdel& cascdel, atf_amc::FCascdel &a, atf_amc::FCascdel &b) {
2533 (void)cascdel;
2534 return a.key < b.key;
2535}
2536
2537// --- atf_amc.FCascdel.tr_child_atree.UpdateDepth
2538static void atf_amc::tr_child_atree_updateDepth(atf_amc::FCascdel& node) {
2539 i32 ldepth = node.tr_child_atree_left != NULL ? node.tr_child_atree_left->tr_child_atree_depth : 0;
2540 i32 rdepth = node.tr_child_atree_right != NULL ? node.tr_child_atree_right->tr_child_atree_depth : 0;
2541 node.tr_child_atree_depth = i32_Max(ldepth, rdepth) + 1;
2542}
2543
2544// --- atf_amc.FCascdel.tr_child_atree.Turn
2545// rotates the tree in from->to direction
2546static void atf_amc::tr_child_atree_Turn(atf_amc::FCascdel& from, atf_amc::FCascdel& to) {
2547 atf_amc::FCascdel* root = to.tr_child_atree_up;
2548 bool dir = root && root->tr_child_atree_left == &to;
2549 tr_child_atree_Connect(root, &from, dir);
2550 dir = to.tr_child_atree_left == &from;
2551 atf_amc::FCascdel* orphan = (dir ? from.tr_child_atree_right : from.tr_child_atree_left);//other side
2552 tr_child_atree_Connect(&from, &to , !dir);
2553 tr_child_atree_Connect(&to, orphan, dir);
2554}
2555
2556// --- atf_amc.FCascdel.tr_child_atree.Connect
2557inline static void atf_amc::tr_child_atree_Connect(atf_amc::FCascdel* parent, atf_amc::FCascdel* child, bool left) {
2558 if(parent){
2559 (left ? parent->tr_child_atree_left : parent->tr_child_atree_right) = child;
2560 }
2561 if(child){
2562 child->tr_child_atree_up = parent;
2563 }
2564}
2565
2566// --- atf_amc.FCascdel.tr_child_atree.RemoveAllImpl
2567// Empty the index. (rows may be deleted if cascdel)
2568void atf_amc::tr_child_atree_RemoveAllImpl(atf_amc::FCascdel& cascdel, atf_amc::FCascdel* root, bool del) {
2569 if(root != NULL){
2570 tr_child_atree_RemoveAllImpl(cascdel, root->tr_child_atree_left, del);
2571 tr_child_atree_RemoveAllImpl(cascdel, root->tr_child_atree_right, del);
2572 tr_child_atree_Disconnect(*root);
2573 root->tr_child_atree_depth = 0;//the pointers are taken care of by Disconnect
2574 root->tr_child_atree_up = (atf_amc::FCascdel*)-1;//the pointers are taken care of by Disconnect
2575 if(del){
2576 cascdel_Delete(*root);
2577 }
2578 }
2579}
2580
2581// --- atf_amc.FCascdel.tr_child_atree.Reinsert
2582// Reinsert a row with modified key(Reheap semantics)
2583void atf_amc::tr_child_atree_Reinsert(atf_amc::FCascdel& cascdel, atf_amc::FCascdel& node) {
2584 tr_child_atree_Remove(cascdel, node);
2585 tr_child_atree_Insert(cascdel, node);
2586}
2587
2588// --- atf_amc.FCascdel.tr_child_atree.FirstGe
2589// Find the first element that is greater or equal to a sortfld value
2590atf_amc::FCascdel* atf_amc::tr_child_atree_FirstGe(atf_amc::FCascdel& cascdel, const u32& val) {
2591 atf_amc::FCascdel* result = cascdel.tr_child_atree_root;
2592 bool left = false;
2593 while(result){
2594 left = !((*result).key < val);
2595 atf_amc::FCascdel* side = left ? result->tr_child_atree_left : result->tr_child_atree_right;
2596 if(side==NULL){
2597 break;
2598 }
2599 result = side;
2600 }
2601 while(result && (*result).key < val){
2602 result = tr_child_atree_Next(*result);
2603 }
2604 return result;
2605}
2606
2607// --- atf_amc.FCascdel.tr_child_atree.LastLt
2608// Find the last element that is smaller or equal to a sortfld value
2609atf_amc::FCascdel* atf_amc::tr_child_atree_LastLt(atf_amc::FCascdel& cascdel, const u32& val) {
2610 atf_amc::FCascdel* result = cascdel.tr_child_atree_root;
2611 bool left = false;
2612 while(result){
2613 left = val < (*result).key;
2614 atf_amc::FCascdel* side = left ? result->tr_child_atree_left : result->tr_child_atree_right;
2615 if(side==NULL){
2616 break;
2617 }
2618 result = side;
2619 }
2620 while(result && !((*result).key < val)){
2621 result = tr_child_atree_Prev(*result);
2622 }
2623 return result;
2624}
2625
2626// --- atf_amc.FCascdel..Init
2627// Set all fields to initial values.
2628void atf_amc::FCascdel_Init(atf_amc::FCascdel& cascdel) {
2629 cascdel.p_parent = NULL;
2630 cascdel.key = u32(0);
2631 cascdel.type = u32(0);
2632 cascdel.child_ptr = NULL;
2633 cascdel.c_child_ptrary_elems = NULL; // (atf_amc.FCascdel.c_child_ptrary)
2634 cascdel.c_child_ptrary_n = 0; // (atf_amc.FCascdel.c_child_ptrary)
2635 cascdel.c_child_ptrary_max = 0; // (atf_amc.FCascdel.c_child_ptrary)
2636 // initialize hash table for atf_amc::FCascdel;
2637 cascdel.ind_child_thash_n = 0; // (atf_amc.FCascdel.ind_child_thash)
2638 cascdel.ind_child_thash_buckets_n = 4; // (atf_amc.FCascdel.ind_child_thash)
2639 cascdel.ind_child_thash_buckets_elems = (atf_amc::FCascdel**)algo_lib::malloc_AllocMem(sizeof(atf_amc::FCascdel*)*cascdel.ind_child_thash_buckets_n); // initial buckets (atf_amc.FCascdel.ind_child_thash)
2640 if (!cascdel.ind_child_thash_buckets_elems) {
2641 FatalErrorExit("out of memory"); // (atf_amc.FCascdel.ind_child_thash)
2642 }
2643 memset(cascdel.ind_child_thash_buckets_elems, 0, sizeof(atf_amc::FCascdel*)*cascdel.ind_child_thash_buckets_n); // (atf_amc.FCascdel.ind_child_thash)
2644 cascdel.bh_child_bheap_max = 0; // (atf_amc.FCascdel.bh_child_bheap)
2645 cascdel.bh_child_bheap_n = 0; // (atf_amc.FCascdel.bh_child_bheap)
2646 cascdel.bh_child_bheap_elems = NULL; // (atf_amc.FCascdel.bh_child_bheap)
2647 cascdel.zd_childlist_head = NULL; // (atf_amc.FCascdel.zd_childlist)
2648 cascdel.zd_childlist_n = 0; // (atf_amc.FCascdel.zd_childlist)
2649 cascdel.zd_childlist_tail = NULL; // (atf_amc.FCascdel.zd_childlist)
2650 cascdel.tr_child_atree_root = NULL; // (atf_amc.FCascdel.tr_child_atree)
2651 cascdel.tr_child_atree_n = 0;
2652 cascdel.cascdel_c_child_ptrary_in_ary = bool(false);
2653 cascdel.ind_child_thash_next = (atf_amc::FCascdel*)-1; // (atf_amc.FCascdel.ind_child_thash) not-in-hash
2654 cascdel.bh_child_bheap_idx = -1; // (atf_amc.FCascdel.bh_child_bheap) not-in-heap
2655 cascdel.zd_childlist_next = (atf_amc::FCascdel*)-1; // (atf_amc.FCascdel.zd_childlist) not-in-list
2656 cascdel.zd_childlist_prev = NULL; // (atf_amc.FCascdel.zd_childlist)
2657 cascdel.tr_child_atree_up = (atf_amc::FCascdel*)-1; // (atf_amc.FCascdel.tr_child_atree) not in tree
2658 cascdel.tr_child_atree_left = NULL;
2659 cascdel.tr_child_atree_right = NULL;
2660 cascdel.tr_child_atree_depth = 0;
2661 cascdel.cascdel_next = (atf_amc::FCascdel*)-1; // (atf_amc.FDb.cascdel) not-in-tpool's freelist
2662}
2663
2664// --- atf_amc.FCascdel.bh_child_bheap_curs.Add
2665static void atf_amc::cascdel_bh_child_bheap_curs_Add(cascdel_bh_child_bheap_curs &curs, atf_amc::FCascdel& row) {
2666 u32 n = curs.temp_n;
2667 int i = n;
2668 curs.temp_n = n+1;
2669 atf_amc::FCascdel* *elems = curs.temp_elems;
2670 while (i>0) {
2671 int j = (i-1)/2;
2672 atf_amc::FCascdel* p = elems[j];
2673 if (!bh_child_bheap_ElemLt((*curs.parent), row,*p)) {
2674 break;
2675 }
2676 elems[i]=p;
2677 i=j;
2678 }
2679 elems[i]=&row;
2680}
2681
2682// --- atf_amc.FCascdel.bh_child_bheap_curs.Reserve
2683void atf_amc::cascdel_bh_child_bheap_curs_Reserve(cascdel_bh_child_bheap_curs &curs, int n) {
2684 if (n > curs.temp_max) {
2685 size_t old_size = sizeof(void*) * curs.temp_max;
2686 size_t new_size = sizeof(void*) * bh_child_bheap_N((*curs.parent));
2687 curs.temp_elems = (atf_amc::FCascdel**)algo_lib::malloc_ReallocMem(curs.temp_elems, old_size, new_size);
2688 if (!curs.temp_elems) {
2689 algo::FatalErrorExit("atf_amc.cursor_out_of_memory func:atf_amc.FCascdel.bh_child_bheap_curs.Reserve");
2690 }
2691 curs.temp_max = bh_child_bheap_N((*curs.parent));
2692 }
2693}
2694
2695// --- atf_amc.FCascdel.bh_child_bheap_curs.Reset
2696// Reset cursor. If HEAP is non-empty, add its top element to CURS.
2697void atf_amc::cascdel_bh_child_bheap_curs_Reset(cascdel_bh_child_bheap_curs &curs, atf_amc::FCascdel &parent) {
2698 curs.parent = &parent;
2699 cascdel_bh_child_bheap_curs_Reserve(curs, bh_child_bheap_N((*curs.parent)));
2700 curs.temp_n = 0;
2701 if (parent.bh_child_bheap_n > 0) {
2702 atf_amc::FCascdel &first = *parent.bh_child_bheap_elems[0];
2703 curs.temp_elems[0] = &first; // insert first element in heap
2704 curs.temp_n = 1;
2705 }
2706}
2707
2708// --- atf_amc.FCascdel.bh_child_bheap_curs.Next
2709// Advance cursor.
2710void atf_amc::cascdel_bh_child_bheap_curs_Next(cascdel_bh_child_bheap_curs &curs) {
2711 atf_amc::FCascdel* *elems = curs.temp_elems;
2712 int n = curs.temp_n;
2713 if (n > 0) {
2714 // remove top element from heap
2715 atf_amc::FCascdel* dead = elems[0];
2716 int i = 0;
2717 atf_amc::FCascdel* last = curs.temp_elems[n-1];
2718 // downheap last elem
2719 do {
2720 atf_amc::FCascdel* choose = last;
2721 int l = i*2+1;
2722 if (l<n) {
2723 atf_amc::FCascdel* el = elems[l];
2724 int r = l+1;
2725 r -= r==n;
2726 atf_amc::FCascdel* er = elems[r];
2727 if (bh_child_bheap_ElemLt((*curs.parent),*er,*el)) {
2728 el = er;
2729 l = r;
2730 }
2731 bool b = bh_child_bheap_ElemLt((*curs.parent),*el,*last);
2732 if (b) choose = el;
2733 if (!b) l = n;
2734 }
2735 elems[i] = choose;
2736 i = l;
2737 } while (i < n);
2738 curs.temp_n = n-1;
2739 int index = dead->bh_child_bheap_idx;
2740 i = (index*2+1);
2741 if (i < bh_child_bheap_N((*curs.parent))) {
2742 atf_amc::FCascdel &elem = *curs.parent->bh_child_bheap_elems[i];
2743 cascdel_bh_child_bheap_curs_Add(curs, elem);
2744 }
2745 if (i+1 < bh_child_bheap_N((*curs.parent))) {
2746 atf_amc::FCascdel &elem = *curs.parent->bh_child_bheap_elems[i + 1];
2747 cascdel_bh_child_bheap_curs_Add(curs, elem);
2748 }
2749 }
2750}
2751
2752// --- atf_amc.FCascdel..Uninit
2753void atf_amc::FCascdel_Uninit(atf_amc::FCascdel& cascdel) {
2754 atf_amc::FCascdel &row = cascdel; (void)row;
2755 tr_child_atree_Cascdel(cascdel); // dmmeta.cascdel:atf_amc.FCascdel.tr_child_atree
2756 zd_childlist_Cascdel(cascdel); // dmmeta.cascdel:atf_amc.FCascdel.zd_childlist
2757 bh_child_bheap_Cascdel(cascdel); // dmmeta.cascdel:atf_amc.FCascdel.bh_child_bheap
2758 ind_child_thash_Cascdel(cascdel); // dmmeta.cascdel:atf_amc.FCascdel.ind_child_thash
2759 c_child_ptrary_Cascdel(cascdel); // dmmeta.cascdel:atf_amc.FCascdel.c_child_ptrary
2760 child_ptr_Cascdel(cascdel); // dmmeta.cascdel:atf_amc.FCascdel.child_ptr
2761 atf_amc::FCascdel* p_p_parent = row.p_parent;
2762 if (p_p_parent) {
2763 child_ptr_Remove(*p_p_parent, row);// remove cascdel from index child_ptr
2764 }
2765 if (p_p_parent) {
2766 c_child_ptrary_Remove(*p_p_parent, row);// remove cascdel from index c_child_ptrary
2767 }
2768 if (p_p_parent) {
2769 ind_child_thash_Remove(*p_p_parent, row);// remove cascdel from index ind_child_thash
2770 }
2771 if (p_p_parent) {
2772 bh_child_bheap_Remove(*p_p_parent, row);// remove cascdel from index bh_child_bheap
2773 }
2774 if (p_p_parent) {
2775 zd_childlist_Remove(*p_p_parent, row);// remove cascdel from index zd_childlist
2776 }
2777 if (p_p_parent) {
2778 tr_child_atree_Remove(*p_p_parent, row);// remove cascdel from index tr_child_atree
2779 }
2780 key_Cleanup(cascdel); // dmmeta.fcleanup:atf_amc.FCascdel.key
2781
2782 // atf_amc.FCascdel.bh_child_bheap.Uninit (Bheap) //
2783 algo_lib::malloc_FreeMem((u8*)cascdel.bh_child_bheap_elems, sizeof(atf_amc::FCascdel*)*cascdel.bh_child_bheap_max); // (atf_amc.FCascdel.bh_child_bheap)
2784
2785 // atf_amc.FCascdel.ind_child_thash.Uninit (Thash) //
2786 algo_lib::malloc_FreeMem(cascdel.ind_child_thash_buckets_elems, sizeof(atf_amc::FCascdel*)*cascdel.ind_child_thash_buckets_n); // (atf_amc.FCascdel.ind_child_thash)
2787
2788 // atf_amc.FCascdel.c_child_ptrary.Uninit (Ptrary) //
2789 algo_lib::malloc_FreeMem(cascdel.c_child_ptrary_elems, sizeof(atf_amc::FCascdel*)*cascdel.c_child_ptrary_max); // (atf_amc.FCascdel.c_child_ptrary)
2790}
2791
2792// --- atf_amc.FCascdel..Print
2793// print string representation of ROW to string STR
2794// cfmt:atf_amc.FCascdel.String printfmt:Tuple
2795void atf_amc::FCascdel_Print(atf_amc::FCascdel& row, algo::cstring& str) {
2796 algo::tempstr temp;
2797 str << "atf_amc.FCascdel";
2798
2799 u32_Print(row.key, temp);
2800 PrintAttrSpaceReset(str,"key", temp);
2801
2802 atf_amc::type_Print(row, temp);
2803 PrintAttrSpaceReset(str,"type", temp);
2804
2805 u64_PrintHex(u64(row.child_ptr), temp, 8, true);
2806 PrintAttrSpaceReset(str,"child_ptr", temp);
2807
2808 bool_Print(row.cascdel_c_child_ptrary_in_ary, temp);
2809 PrintAttrSpaceReset(str,"cascdel_c_child_ptrary_in_ary", temp);
2810}
2811
2812// --- atf_amc.FCstring.msghdr.CopyOut
2813// Copy fields out of row
2814void atf_amc::cstring_CopyOut(atf_amc::FCstring &row, atf_amc::Cstring &out) {
2815 out.str = row.str;
2816}
2817
2818// --- atf_amc.FCstring.msghdr.CopyIn
2819// Copy fields in to row
2820void atf_amc::cstring_CopyIn(atf_amc::FCstring &row, atf_amc::Cstring &in) {
2821 row.str = in.str;
2822}
2823
2824// --- atf_amc.FCstring..Uninit
2825void atf_amc::FCstring_Uninit(atf_amc::FCstring& cstring) {
2826 atf_amc::FCstring &row = cstring; (void)row;
2827 ind_cstring_Remove(row); // remove cstring from index ind_cstring
2828}
2829
2830// --- atf_amc.FListtype.base.CopyOut
2831// Copy fields out of row
2832void atf_amc::listtype_CopyOut(atf_amc::FListtype &row, dmmeta::Listtype &out) {
2833 out.listtype = row.listtype;
2834 out.circular = row.circular;
2835 out.haveprev = row.haveprev;
2836 out.instail = row.instail;
2837 out.comment = row.comment;
2838}
2839
2840// --- atf_amc.FListtype.base.CopyIn
2841// Copy fields in to row
2842void atf_amc::listtype_CopyIn(atf_amc::FListtype &row, dmmeta::Listtype &in) {
2843 row.listtype = in.listtype;
2844 row.circular = in.circular;
2845 row.haveprev = in.haveprev;
2846 row.instail = in.instail;
2847 row.comment = in.comment;
2848}
2849
2850// --- atf_amc.trace..Init
2851// Set all fields to initial values.
2852void atf_amc::trace_Init(atf_amc::trace& parent) {
2853 parent.step_bh_typec = u64(0);
2854 parent.step_bh_typec_cycles = u64(0);
2855 parent.step_zsl_h_typec = u64(0);
2856 parent.step_zsl_h_typec_cycles = u64(0);
2857 parent.step_zs_t_typec = u64(0);
2858 parent.step_zs_t_typec_cycles = u64(0);
2859 parent.step_csl_h_typec = u64(0);
2860 parent.step_csl_h_typec_cycles = u64(0);
2861 parent.step_cs_t_typec = u64(0);
2862 parent.step_cs_t_typec_cycles = u64(0);
2863 parent.step_cd_in_msg = u64(0);
2864 parent.step_cd_in_msg_cycles = u64(0);
2865}
2866
2867// --- atf_amc.trace..Print
2868// print string representation of ROW to string STR
2869// cfmt:atf_amc.trace.String printfmt:Tuple
2870void atf_amc::trace_Print(atf_amc::trace& row, algo::cstring& str) {
2871 algo::tempstr temp;
2872 str << "atf_amc.trace";
2873
2874 u64_Print(row.step_bh_typec, temp);
2875 PrintAttrSpaceReset(str,"step_bh_typec", temp);
2876
2877 u64_Print(row.step_bh_typec_cycles, temp);
2878 PrintAttrSpaceReset(str,"step_bh_typec_cycles", temp);
2879
2880 u64_Print(row.step_zsl_h_typec, temp);
2881 PrintAttrSpaceReset(str,"step_zsl_h_typec", temp);
2882
2883 u64_Print(row.step_zsl_h_typec_cycles, temp);
2884 PrintAttrSpaceReset(str,"step_zsl_h_typec_cycles", temp);
2885
2886 u64_Print(row.step_zs_t_typec, temp);
2887 PrintAttrSpaceReset(str,"step_zs_t_typec", temp);
2888
2889 u64_Print(row.step_zs_t_typec_cycles, temp);
2890 PrintAttrSpaceReset(str,"step_zs_t_typec_cycles", temp);
2891
2892 u64_Print(row.step_csl_h_typec, temp);
2893 PrintAttrSpaceReset(str,"step_csl_h_typec", temp);
2894
2895 u64_Print(row.step_csl_h_typec_cycles, temp);
2896 PrintAttrSpaceReset(str,"step_csl_h_typec_cycles", temp);
2897
2898 u64_Print(row.step_cs_t_typec, temp);
2899 PrintAttrSpaceReset(str,"step_cs_t_typec", temp);
2900
2901 u64_Print(row.step_cs_t_typec_cycles, temp);
2902 PrintAttrSpaceReset(str,"step_cs_t_typec_cycles", temp);
2903
2904 u64_Print(row.step_cd_in_msg, temp);
2905 PrintAttrSpaceReset(str,"step_cd_in_msg", temp);
2906
2907 u64_Print(row.step_cd_in_msg_cycles, temp);
2908 PrintAttrSpaceReset(str,"step_cd_in_msg_cycles", temp);
2909}
2910
2911// --- atf_amc.FDb.bh_typec.Dealloc
2912// Remove all elements from heap and free memory used by the array.
2913void atf_amc::bh_typec_Dealloc() {
2914 bh_typec_RemoveAll();
2915 algo_lib::malloc_FreeMem(_db.bh_typec_elems, sizeof(atf_amc::FTypeC*)*_db.bh_typec_max);
2916 _db.bh_typec_max = 0;
2917 _db.bh_typec_elems = NULL;
2918}
2919
2920// --- atf_amc.FDb.bh_typec.Downheap
2921// Find new location for ROW starting at IDX
2922// NOTE: Rest of heap is rearranged, but pointer to ROW is NOT stored in array.
2923static int atf_amc::bh_typec_Downheap(atf_amc::FTypeC& row, int idx) {
2924 atf_amc::FTypeC* *elems = _db.bh_typec_elems;
2925 int n = _db.bh_typec_n;
2926 int child = idx*2+1;
2927 while (child < n) {
2928 atf_amc::FTypeC* p = elems[child]; // left child
2929 int rchild = child+1;
2930 if (rchild < n) {
2931 atf_amc::FTypeC* q = elems[rchild]; // right child
2932 if (bh_typec_ElemLt(*q,*p)) {
2933 child = rchild;
2934 p = q;
2935 }
2936 }
2937 if (!bh_typec_ElemLt(*p,row)) {
2938 break;
2939 }
2940 p->bh_typec_idx = idx;
2941 elems[idx] = p;
2942 idx = child;
2943 child = idx*2+1;
2944 }
2945 return idx;
2946}
2947
2948// --- atf_amc.FDb.bh_typec.Insert
2949// Insert row. Row must not already be in index. If row is already in index, do nothing.
2950void atf_amc::bh_typec_Insert(atf_amc::FTypeC& row) {
2951 if (LIKELY(row.bh_typec_idx == -1)) {
2952 bh_typec_Reserve(1);
2953 int n = _db.bh_typec_n;
2954 _db.bh_typec_n = n + 1;
2955 int new_idx = bh_typec_Upheap(row, n);
2956 row.bh_typec_idx = new_idx;
2957 _db.bh_typec_elems[new_idx] = &row;
2958 if (new_idx==0) {
2959 bh_typec_FirstChanged();
2960 }
2961 }
2962}
2963
2964// --- atf_amc.FDb.bh_typec.Reheap
2965// If row is in heap, update its position. If row is not in heap, insert it.
2966// Return new position of item in the heap (0=top)
2967// If first item of the is changed, update fstep:atf_amc.FDb.bh_typec
2968i32 atf_amc::bh_typec_Reheap(atf_amc::FTypeC& row) {
2969 int old_idx = row.bh_typec_idx;
2970 bool isnew = old_idx == -1;
2971 if (isnew) {
2972 bh_typec_Reserve(1);
2973 old_idx = _db.bh_typec_n++;
2974 }
2975 int new_idx = bh_typec_Upheap(row, old_idx);
2976 if (!isnew && new_idx == old_idx) {
2977 new_idx = bh_typec_Downheap(row, old_idx);
2978 }
2979 row.bh_typec_idx = new_idx;
2980 _db.bh_typec_elems[new_idx] = &row;
2981 bool changed = new_idx==0 || old_idx==0;
2982 if (changed) {
2983 bh_typec_FirstChanged();
2984 }
2985 return new_idx;
2986}
2987
2988// --- atf_amc.FDb.bh_typec.ReheapFirst
2989// Key of first element in the heap changed. Move it.
2990// This function does not check the insert condition.
2991// Return new position of item in the heap (0=top).
2992// Heap must be non-empty or behavior is undefined.
2993// Update fstep:atf_amc.FDb.bh_typec
2994i32 atf_amc::bh_typec_ReheapFirst() {
2995 atf_amc::FTypeC &row = *_db.bh_typec_elems[0];
2996 i32 new_idx = bh_typec_Downheap(row, 0);
2997 row.bh_typec_idx = new_idx;
2998 _db.bh_typec_elems[new_idx] = &row;
2999 if (new_idx != 0) {
3000 bh_typec_FirstChanged();
3001 }
3002 return new_idx;
3003}
3004
3005// --- atf_amc.FDb.bh_typec.Remove
3006// Remove element from index. If element is not in index, do nothing.
3007void atf_amc::bh_typec_Remove(atf_amc::FTypeC& row) {
3008 if (bh_typec_InBheapQ(row)) {
3009 int old_idx = row.bh_typec_idx;
3010 if (_db.bh_typec_elems[old_idx] == &row) { // sanity check: heap points back to row
3011 row.bh_typec_idx = -1; // mark not in heap
3012 i32 n = _db.bh_typec_n - 1; // index of last element in heap
3013 _db.bh_typec_n = n; // decrease count
3014 if (old_idx != n) {
3015 atf_amc::FTypeC *elem = _db.bh_typec_elems[n];
3016 int new_idx = bh_typec_Upheap(*elem, old_idx);
3017 if (new_idx == old_idx) {
3018 new_idx = bh_typec_Downheap(*elem, old_idx);
3019 }
3020 elem->bh_typec_idx = new_idx;
3021 _db.bh_typec_elems[new_idx] = elem;
3022 }
3023 if (old_idx == 0) {
3024 bh_typec_FirstChanged();
3025 }
3026 }
3027 }
3028}
3029
3030// --- atf_amc.FDb.bh_typec.RemoveAll
3031// Remove all elements from binary heap
3032void atf_amc::bh_typec_RemoveAll() {
3033 int n = _db.bh_typec_n;
3034 for (int i = n - 1; i>=0; i--) {
3035 _db.bh_typec_elems[i]->bh_typec_idx = -1; // mark not-in-heap
3036 }
3037 _db.bh_typec_n = 0;
3038 if (n > 0) {
3039 bh_typec_FirstChanged();
3040 }
3041}
3042
3043// --- atf_amc.FDb.bh_typec.RemoveFirst
3044// If index is empty, return NULL. Otherwise remove and return first key in index.
3045// Call 'head changed' trigger.
3046atf_amc::FTypeC* atf_amc::bh_typec_RemoveFirst() {
3047 atf_amc::FTypeC *row = NULL;
3048 if (_db.bh_typec_n > 0) {
3049 row = _db.bh_typec_elems[0];
3050 row->bh_typec_idx = -1; // mark not in heap
3051 i32 n = _db.bh_typec_n - 1; // index of last element in heap
3052 _db.bh_typec_n = n; // decrease count
3053 if (n) {
3054 atf_amc::FTypeC &elem = *_db.bh_typec_elems[n];
3055 int new_idx = bh_typec_Downheap(elem, 0);
3056 elem.bh_typec_idx = new_idx;
3057 _db.bh_typec_elems[new_idx] = &elem;
3058 }
3059 bh_typec_FirstChanged();
3060 }
3061 return row;
3062}
3063
3064// --- atf_amc.FDb.bh_typec.Reserve
3065// Reserve space in index for N more elements
3066void atf_amc::bh_typec_Reserve(int n) {
3067 i32 old_max = _db.bh_typec_max;
3068 if (UNLIKELY(_db.bh_typec_n + n > old_max)) {
3069 u32 new_max = u32_Max(4, old_max * 2);
3070 u32 old_size = old_max * sizeof(atf_amc::FTypeC*);
3071 u32 new_size = new_max * sizeof(atf_amc::FTypeC*);
3072 void *new_mem = algo_lib::malloc_ReallocMem(_db.bh_typec_elems, old_size, new_size);
3073 if (UNLIKELY(!new_mem)) {
3074 FatalErrorExit("atf_amc.out_of_memory field:atf_amc.FDb.bh_typec");
3075 }
3076 _db.bh_typec_elems = (atf_amc::FTypeC**)new_mem;
3077 _db.bh_typec_max = new_max;
3078 }
3079}
3080
3081// --- atf_amc.FDb.bh_typec.Upheap
3082// Find and return index of new location for element ROW in the heap, starting at index IDX.
3083// Move any elements along the way but do not modify ROW.
3084static int atf_amc::bh_typec_Upheap(atf_amc::FTypeC& row, int idx) {
3085 atf_amc::FTypeC* *elems = _db.bh_typec_elems;
3086 while (idx>0) {
3087 int j = (idx-1)/2;
3088 atf_amc::FTypeC* p = elems[j];
3089 if (!bh_typec_ElemLt(row, *p)) {
3090 break;
3091 }
3092 p->bh_typec_idx = idx;
3093 elems[idx] = p;
3094 idx = j;
3095 }
3096 return idx;
3097}
3098
3099// --- atf_amc.FDb.bh_typec.ElemLt
3100inline static bool atf_amc::bh_typec_ElemLt(atf_amc::FTypeC &a, atf_amc::FTypeC &b) {
3101 (void)_db;
3102 return a.typec < b.typec;
3103}
3104
3105// --- atf_amc.FDb.bh_typec.UpdateCycles
3106// Update cycles count from previous clock capture
3107void atf_amc::bh_typec_UpdateCycles() {
3108 u64 cur_cycles = algo::get_cycles();
3109 u64 prev_cycles = algo_lib::_db.clock.value;
3110 ++atf_amc::_db.trace.step_bh_typec;
3111 atf_amc::_db.trace.step_bh_typec_cycles += cur_cycles - prev_cycles;
3112 algo_lib::_db.clock = algo::SchedTime(cur_cycles);
3113}
3114
3115// --- atf_amc.FDb.zdl_h_typec.Insert
3116// Insert row into linked list. If row is already in linked list, do nothing.
3117void atf_amc::zdl_h_typec_Insert(atf_amc::FTypeC& row) {
3118 if (!zdl_h_typec_InLlistQ(row)) {
3119 atf_amc::FTypeC* old_head = _db.zdl_h_typec_head;
3120 row.zdl_h_typec_prev = NULL;
3121 row.zdl_h_typec_next = old_head;
3122 _db.zdl_h_typec_head = &row;
3123 atf_amc::FTypeC **new_row_a = &old_head->zdl_h_typec_prev;
3124 atf_amc::FTypeC **new_row_b = &_db.zdl_h_typec_tail;
3125 atf_amc::FTypeC **new_row = old_head ? new_row_a : new_row_b;
3126 *new_row = &row;
3127 _db.zdl_h_typec_n++;
3128 }
3129}
3130
3131// --- atf_amc.FDb.zdl_h_typec.Remove
3132// Remove element from index. If element is not in index, do nothing.
3133void atf_amc::zdl_h_typec_Remove(atf_amc::FTypeC& row) {
3134 if (zdl_h_typec_InLlistQ(row)) {
3135 atf_amc::FTypeC* old_head = _db.zdl_h_typec_head;
3136 (void)old_head; // in case it's not used
3137 atf_amc::FTypeC* prev = row.zdl_h_typec_prev;
3138 atf_amc::FTypeC* next = row.zdl_h_typec_next;
3139 // if element is first, adjust list head; otherwise, adjust previous element's next
3140 atf_amc::FTypeC **new_next_a = &prev->zdl_h_typec_next;
3141 atf_amc::FTypeC **new_next_b = &_db.zdl_h_typec_head;
3142 atf_amc::FTypeC **new_next = prev ? new_next_a : new_next_b;
3143 *new_next = next;
3144 // if element is last, adjust list tail; otherwise, adjust next element's prev
3145 atf_amc::FTypeC **new_prev_a = &next->zdl_h_typec_prev;
3146 atf_amc::FTypeC **new_prev_b = &_db.zdl_h_typec_tail;
3147 atf_amc::FTypeC **new_prev = next ? new_prev_a : new_prev_b;
3148 *new_prev = prev;
3149 _db.zdl_h_typec_n--;
3150 row.zdl_h_typec_next=(atf_amc::FTypeC*)-1; // not-in-list
3151 }
3152}
3153
3154// --- atf_amc.FDb.zdl_h_typec.RemoveAll
3155// Empty the index. (The rows are not deleted)
3156void atf_amc::zdl_h_typec_RemoveAll() {
3157 atf_amc::FTypeC* row = _db.zdl_h_typec_head;
3158 _db.zdl_h_typec_head = NULL;
3159 _db.zdl_h_typec_tail = NULL;
3160 _db.zdl_h_typec_n = 0;
3161 while (row) {
3162 atf_amc::FTypeC* row_next = row->zdl_h_typec_next;
3163 row->zdl_h_typec_next = (atf_amc::FTypeC*)-1;
3164 row->zdl_h_typec_prev = NULL;
3165 row = row_next;
3166 }
3167}
3168
3169// --- atf_amc.FDb.zdl_h_typec.RemoveFirst
3170// If linked list is empty, return NULL. Otherwise unlink and return pointer to first element.
3171atf_amc::FTypeC* atf_amc::zdl_h_typec_RemoveFirst() {
3172 atf_amc::FTypeC *row = NULL;
3173 row = _db.zdl_h_typec_head;
3174 if (row) {
3175 atf_amc::FTypeC *next = row->zdl_h_typec_next;
3176 _db.zdl_h_typec_head = next;
3177 atf_amc::FTypeC **new_end_a = &next->zdl_h_typec_prev;
3178 atf_amc::FTypeC **new_end_b = &_db.zdl_h_typec_tail;
3179 atf_amc::FTypeC **new_end = next ? new_end_a : new_end_b;
3180 *new_end = NULL;
3181 _db.zdl_h_typec_n--;
3182 row->zdl_h_typec_next = (atf_amc::FTypeC*)-1; // mark as not-in-list
3183 }
3184 return row;
3185}
3186
3187// --- atf_amc.FDb.zd_t_typec.Insert
3188// Insert row into linked list. If row is already in linked list, do nothing.
3189void atf_amc::zd_t_typec_Insert(atf_amc::FTypeC& row) {
3190 if (!zd_t_typec_InLlistQ(row)) {
3191 atf_amc::FTypeC* old_tail = _db.zd_t_typec_tail;
3192 row.zd_t_typec_next = NULL;
3193 row.zd_t_typec_prev = old_tail;
3194 _db.zd_t_typec_tail = &row;
3195 atf_amc::FTypeC **new_row_a = &old_tail->zd_t_typec_next;
3196 atf_amc::FTypeC **new_row_b = &_db.zd_t_typec_head;
3197 atf_amc::FTypeC **new_row = old_tail ? new_row_a : new_row_b;
3198 *new_row = &row;
3199 _db.zd_t_typec_n++;
3200 }
3201}
3202
3203// --- atf_amc.FDb.zd_t_typec.Remove
3204// Remove element from index. If element is not in index, do nothing.
3205void atf_amc::zd_t_typec_Remove(atf_amc::FTypeC& row) {
3206 if (zd_t_typec_InLlistQ(row)) {
3207 atf_amc::FTypeC* old_head = _db.zd_t_typec_head;
3208 (void)old_head; // in case it's not used
3209 atf_amc::FTypeC* prev = row.zd_t_typec_prev;
3210 atf_amc::FTypeC* next = row.zd_t_typec_next;
3211 // if element is first, adjust list head; otherwise, adjust previous element's next
3212 atf_amc::FTypeC **new_next_a = &prev->zd_t_typec_next;
3213 atf_amc::FTypeC **new_next_b = &_db.zd_t_typec_head;
3214 atf_amc::FTypeC **new_next = prev ? new_next_a : new_next_b;
3215 *new_next = next;
3216 // if element is last, adjust list tail; otherwise, adjust next element's prev
3217 atf_amc::FTypeC **new_prev_a = &next->zd_t_typec_prev;
3218 atf_amc::FTypeC **new_prev_b = &_db.zd_t_typec_tail;
3219 atf_amc::FTypeC **new_prev = next ? new_prev_a : new_prev_b;
3220 *new_prev = prev;
3221 _db.zd_t_typec_n--;
3222 row.zd_t_typec_next=(atf_amc::FTypeC*)-1; // not-in-list
3223 }
3224}
3225
3226// --- atf_amc.FDb.zd_t_typec.RemoveAll
3227// Empty the index. (The rows are not deleted)
3228void atf_amc::zd_t_typec_RemoveAll() {
3229 atf_amc::FTypeC* row = _db.zd_t_typec_head;
3230 _db.zd_t_typec_head = NULL;
3231 _db.zd_t_typec_tail = NULL;
3232 _db.zd_t_typec_n = 0;
3233 while (row) {
3234 atf_amc::FTypeC* row_next = row->zd_t_typec_next;
3235 row->zd_t_typec_next = (atf_amc::FTypeC*)-1;
3236 row->zd_t_typec_prev = NULL;
3237 row = row_next;
3238 }
3239}
3240
3241// --- atf_amc.FDb.zd_t_typec.RemoveFirst
3242// If linked list is empty, return NULL. Otherwise unlink and return pointer to first element.
3243atf_amc::FTypeC* atf_amc::zd_t_typec_RemoveFirst() {
3244 atf_amc::FTypeC *row = NULL;
3245 row = _db.zd_t_typec_head;
3246 if (row) {
3247 atf_amc::FTypeC *next = row->zd_t_typec_next;
3248 _db.zd_t_typec_head = next;
3249 atf_amc::FTypeC **new_end_a = &next->zd_t_typec_prev;
3250 atf_amc::FTypeC **new_end_b = &_db.zd_t_typec_tail;
3251 atf_amc::FTypeC **new_end = next ? new_end_a : new_end_b;
3252 *new_end = NULL;
3253 _db.zd_t_typec_n--;
3254 row->zd_t_typec_next = (atf_amc::FTypeC*)-1; // mark as not-in-list
3255 }
3256 return row;
3257}
3258
3259// --- atf_amc.FDb.zd_typed.Insert
3260// Insert row into linked list. If row is already in linked list, do nothing.
3261void atf_amc::zd_typed_Insert(atf_amc::FTypeD& row) {
3262 if (!zd_typed_InLlistQ(row)) {
3263 atf_amc::FTypeD* old_tail = _db.zd_typed_tail;
3264 row.zd_typed_next = NULL;
3265 row.zd_typed_prev = old_tail;
3266 _db.zd_typed_tail = &row;
3267 atf_amc::FTypeD **new_row_a = &old_tail->zd_typed_next;
3268 atf_amc::FTypeD **new_row_b = &_db.zd_typed_head;
3269 atf_amc::FTypeD **new_row = old_tail ? new_row_a : new_row_b;
3270 *new_row = &row;
3271 _db.zd_typed_n++;
3272 }
3273}
3274
3275// --- atf_amc.FDb.zd_typed.Remove
3276// Remove element from index. If element is not in index, do nothing.
3277void atf_amc::zd_typed_Remove(atf_amc::FTypeD& row) {
3278 if (zd_typed_InLlistQ(row)) {
3279 atf_amc::FTypeD* old_head = _db.zd_typed_head;
3280 (void)old_head; // in case it's not used
3281 atf_amc::FTypeD* prev = row.zd_typed_prev;
3282 atf_amc::FTypeD* next = row.zd_typed_next;
3283 // if element is first, adjust list head; otherwise, adjust previous element's next
3284 atf_amc::FTypeD **new_next_a = &prev->zd_typed_next;
3285 atf_amc::FTypeD **new_next_b = &_db.zd_typed_head;
3286 atf_amc::FTypeD **new_next = prev ? new_next_a : new_next_b;
3287 *new_next = next;
3288 // if element is last, adjust list tail; otherwise, adjust next element's prev
3289 atf_amc::FTypeD **new_prev_a = &next->zd_typed_prev;
3290 atf_amc::FTypeD **new_prev_b = &_db.zd_typed_tail;
3291 atf_amc::FTypeD **new_prev = next ? new_prev_a : new_prev_b;
3292 *new_prev = prev;
3293 _db.zd_typed_n--;
3294 row.zd_typed_next=(atf_amc::FTypeD*)-1; // not-in-list
3295 }
3296}
3297
3298// --- atf_amc.FDb.zd_typed.RemoveAll
3299// Empty the index. (The rows are not deleted)
3300void atf_amc::zd_typed_RemoveAll() {
3301 atf_amc::FTypeD* row = _db.zd_typed_head;
3302 _db.zd_typed_head = NULL;
3303 _db.zd_typed_tail = NULL;
3304 _db.zd_typed_n = 0;
3305 while (row) {
3306 atf_amc::FTypeD* row_next = row->zd_typed_next;
3307 row->zd_typed_next = (atf_amc::FTypeD*)-1;
3308 row->zd_typed_prev = NULL;
3309 row = row_next;
3310 }
3311}
3312
3313// --- atf_amc.FDb.zd_typed.RemoveFirst
3314// If linked list is empty, return NULL. Otherwise unlink and return pointer to first element.
3315atf_amc::FTypeD* atf_amc::zd_typed_RemoveFirst() {
3316 atf_amc::FTypeD *row = NULL;
3317 row = _db.zd_typed_head;
3318 if (row) {
3319 atf_amc::FTypeD *next = row->zd_typed_next;
3320 _db.zd_typed_head = next;
3321 atf_amc::FTypeD **new_end_a = &next->zd_typed_prev;
3322 atf_amc::FTypeD **new_end_b = &_db.zd_typed_tail;
3323 atf_amc::FTypeD **new_end = next ? new_end_a : new_end_b;
3324 *new_end = NULL;
3325 _db.zd_typed_n--;
3326 row->zd_typed_next = (atf_amc::FTypeD*)-1; // mark as not-in-list
3327 }
3328 return row;
3329}
3330
3331// --- atf_amc.FDb.zs_t_typed.Insert
3332// Insert row into linked list. If row is already in linked list, do nothing.
3333void atf_amc::zs_t_typed_Insert(atf_amc::FTypeD& row) {
3334 if (!zs_t_typed_InLlistQ(row)) {
3335 atf_amc::FTypeD* old_tail = _db.zs_t_typed_tail;
3336 row.zs_t_typed_next = NULL;
3337 _db.zs_t_typed_tail = &row;
3338 atf_amc::FTypeD **new_row_a = &old_tail->zs_t_typed_next;
3339 atf_amc::FTypeD **new_row_b = &_db.zs_t_typed_head;
3340 atf_amc::FTypeD **new_row = old_tail ? new_row_a : new_row_b;
3341 *new_row = &row;
3342 _db.zs_t_typed_n++;
3343 }
3344}
3345
3346// --- atf_amc.FDb.zs_t_typed.Remove
3347// Remove element from index. If element is not in index, do nothing.
3348// Since the list is singly-linked, use linear search to locate the element.
3349void atf_amc::zs_t_typed_Remove(atf_amc::FTypeD& row) {
3350 if (zs_t_typed_InLlistQ(row)) {
3351 atf_amc::FTypeD* old_head = _db.zs_t_typed_head;
3352 (void)old_head; // in case it's not used
3353 atf_amc::FTypeD* prev=NULL;
3354 atf_amc::FTypeD* cur = _db.zs_t_typed_head;
3355 while (cur) { // search for element by pointer
3356 atf_amc::FTypeD* next = cur->zs_t_typed_next;
3357 if (cur == &row) {
3358 _db.zs_t_typed_n--; // adjust count
3359
3360 if (!next) {
3361 _db.zs_t_typed_tail = prev; // adjust tail pointer
3362 }
3363 // disconnect element from linked list
3364 if (prev) {
3365 prev->zs_t_typed_next = next;
3366 } else {
3367 _db.zs_t_typed_head = next;
3368 }
3369 row.zs_t_typed_next = (atf_amc::FTypeD*)-1; // not-in-list
3370 break;
3371 }
3372 prev = cur;
3373 cur = next;
3374 }
3375 }
3376}
3377
3378// --- atf_amc.FDb.zs_t_typed.RemoveAll
3379// Empty the index. (The rows are not deleted)
3380void atf_amc::zs_t_typed_RemoveAll() {
3381 atf_amc::FTypeD* row = _db.zs_t_typed_head;
3382 _db.zs_t_typed_head = NULL;
3383 _db.zs_t_typed_tail = NULL;
3384 _db.zs_t_typed_n = 0;
3385 while (row) {
3386 atf_amc::FTypeD* row_next = row->zs_t_typed_next;
3387 row->zs_t_typed_next = (atf_amc::FTypeD*)-1;
3388 row = row_next;
3389 }
3390}
3391
3392// --- atf_amc.FDb.zs_t_typed.RemoveFirst
3393// If linked list is empty, return NULL. Otherwise unlink and return pointer to first element.
3394atf_amc::FTypeD* atf_amc::zs_t_typed_RemoveFirst() {
3395 atf_amc::FTypeD *row = NULL;
3396 row = _db.zs_t_typed_head;
3397 if (row) {
3398 atf_amc::FTypeD *next = row->zs_t_typed_next;
3399 _db.zs_t_typed_head = next;
3400 // clear list's tail pointer if list is empty.
3401 if (!next) {
3402 _db.zs_t_typed_tail = NULL;
3403 }
3404 _db.zs_t_typed_n--;
3405 row->zs_t_typed_next = (atf_amc::FTypeD*)-1; // mark as not-in-list
3406 }
3407 return row;
3408}
3409
3410// --- atf_amc.FDb.cd_typed.Insert
3411// Insert row into linked list. If row is already in linked list, do nothing.
3412void atf_amc::cd_typed_Insert(atf_amc::FTypeD& row) {
3413 if (!cd_typed_InLlistQ(row)) {
3414 if (_db.cd_typed_head) {
3415 row.cd_typed_next = _db.cd_typed_head;
3416 row.cd_typed_prev = _db.cd_typed_head->cd_typed_prev;
3417 row.cd_typed_prev->cd_typed_next = &row;
3418 row.cd_typed_next->cd_typed_prev = &row;
3419 } else {
3420 row.cd_typed_next = &row;
3421 row.cd_typed_prev = &row;
3422 _db.cd_typed_head = &row;
3423 }
3424 _db.cd_typed_n++;
3425 }
3426}
3427
3428// --- atf_amc.FDb.cd_typed.Remove
3429// Remove element from index. If element is not in index, do nothing.
3430void atf_amc::cd_typed_Remove(atf_amc::FTypeD& row) {
3431 if (cd_typed_InLlistQ(row)) {
3432 atf_amc::FTypeD* old_head = _db.cd_typed_head;
3433 (void)old_head; // in case it's not used
3434 atf_amc::FTypeD *oldnext = row.cd_typed_next;
3435 atf_amc::FTypeD *oldprev = row.cd_typed_prev;
3436 oldnext->cd_typed_prev = oldprev; // remove element from list
3437 oldprev->cd_typed_next = oldnext;
3438 _db.cd_typed_n--; // adjust count
3439 if (&row == _db.cd_typed_head) {
3440 _db.cd_typed_head = oldnext==&row ? NULL : oldnext; // adjust list head
3441 }
3442 row.cd_typed_next = (atf_amc::FTypeD*)-1; // mark element as not-in-list);
3443 row.cd_typed_prev = NULL; // clear back-pointer
3444 }
3445}
3446
3447// --- atf_amc.FDb.cd_typed.RemoveAll
3448// Empty the index. (The rows are not deleted)
3449void atf_amc::cd_typed_RemoveAll() {
3450 atf_amc::FTypeD* row = _db.cd_typed_head;
3451 atf_amc::FTypeD* head = _db.cd_typed_head;
3452 _db.cd_typed_head = NULL;
3453 _db.cd_typed_n = 0;
3454 while (row) {
3455 atf_amc::FTypeD* row_next = row->cd_typed_next;
3456 row->cd_typed_next = (atf_amc::FTypeD*)-1;
3457 row->cd_typed_prev = NULL;
3458 row = row_next != head ? row_next : NULL;
3459 }
3460}
3461
3462// --- atf_amc.FDb.cd_typed.RemoveFirst
3463// If linked list is empty, return NULL. Otherwise unlink and return pointer to first element.
3464atf_amc::FTypeD* atf_amc::cd_typed_RemoveFirst() {
3465 atf_amc::FTypeD *row = NULL;
3466 row = _db.cd_typed_head;
3467 if (row) {
3468 bool hasmore = row!=row->cd_typed_next;
3469 _db.cd_typed_head = hasmore ? row->cd_typed_next : NULL;
3470 row->cd_typed_next->cd_typed_prev = row->cd_typed_prev;
3471 row->cd_typed_prev->cd_typed_next = row->cd_typed_next;
3472 row->cd_typed_prev = NULL;
3473 _db.cd_typed_n--;
3474 row->cd_typed_next = (atf_amc::FTypeD*)-1; // mark as not-in-list
3475 }
3476 return row;
3477}
3478
3479// --- atf_amc.FDb.cd_typed.RotateFirst
3480// If linked list is empty, return NULL.
3481// Otherwise return head item and advance head to the next item.
3482atf_amc::FTypeD* atf_amc::cd_typed_RotateFirst() {
3483 atf_amc::FTypeD *row = NULL;
3484 row = _db.cd_typed_head;
3485 if (row) {
3486 _db.cd_typed_head = row->cd_typed_next;
3487 }
3488 return row;
3489}
3490
3491// --- atf_amc.FDb.zsl_h_typec.Insert
3492// Insert row into linked list. If row is already in linked list, do nothing.
3493void atf_amc::zsl_h_typec_Insert(atf_amc::FTypeC& row) {
3494 if (!zsl_h_typec_InLlistQ(row)) {
3495 atf_amc::FTypeC* old_head = _db.zsl_h_typec_head;
3496 row.zsl_h_typec_next = old_head;
3497 _db.zsl_h_typec_head = &row;
3498 if (!old_head) {
3499 _db.zsl_h_typec_tail = &row;
3500 }
3501 _db.zsl_h_typec_n++;
3502 if (_db.zsl_h_typec_head == &row) {
3503 zsl_h_typec_FirstChanged();
3504 }
3505 }
3506}
3507
3508// --- atf_amc.FDb.zsl_h_typec.Remove
3509// Remove element from index. If element is not in index, do nothing.
3510// Since the list is singly-linked, use linear search to locate the element.
3511void atf_amc::zsl_h_typec_Remove(atf_amc::FTypeC& row) {
3512 if (zsl_h_typec_InLlistQ(row)) {
3513 atf_amc::FTypeC* old_head = _db.zsl_h_typec_head;
3514 (void)old_head; // in case it's not used
3515 atf_amc::FTypeC* prev=NULL;
3516 atf_amc::FTypeC* cur = _db.zsl_h_typec_head;
3517 while (cur) { // search for element by pointer
3518 atf_amc::FTypeC* next = cur->zsl_h_typec_next;
3519 if (cur == &row) {
3520 _db.zsl_h_typec_n--; // adjust count
3521
3522 if (!next) {
3523 _db.zsl_h_typec_tail = prev; // adjust tail pointer
3524 }
3525 // disconnect element from linked list
3526 if (prev) {
3527 prev->zsl_h_typec_next = next;
3528 } else {
3529 _db.zsl_h_typec_head = next;
3530 }
3531 row.zsl_h_typec_next = (atf_amc::FTypeC*)-1; // not-in-list
3532 break;
3533 }
3534 prev = cur;
3535 cur = next;
3536 }
3537 if (old_head != _db.zsl_h_typec_head) {
3538 zsl_h_typec_FirstChanged();
3539 }
3540 }
3541}
3542
3543// --- atf_amc.FDb.zsl_h_typec.RemoveAll
3544// Empty the index. (The rows are not deleted)
3545void atf_amc::zsl_h_typec_RemoveAll() {
3546 atf_amc::FTypeC* row = _db.zsl_h_typec_head;
3547 _db.zsl_h_typec_head = NULL;
3548 _db.zsl_h_typec_tail = NULL;
3549 _db.zsl_h_typec_n = 0;
3550 bool do_fire = (NULL != row);
3551 while (row) {
3552 atf_amc::FTypeC* row_next = row->zsl_h_typec_next;
3553 row->zsl_h_typec_next = (atf_amc::FTypeC*)-1;
3554 row = row_next;
3555 }
3556 if (do_fire) {
3557 zsl_h_typec_FirstChanged();
3558 }
3559}
3560
3561// --- atf_amc.FDb.zsl_h_typec.RemoveFirst
3562// If linked list is empty, return NULL. Otherwise unlink and return pointer to first element.
3563// Call FirstChanged trigger.
3564atf_amc::FTypeC* atf_amc::zsl_h_typec_RemoveFirst() {
3565 atf_amc::FTypeC *row = NULL;
3566 row = _db.zsl_h_typec_head;
3567 if (row) {
3568 atf_amc::FTypeC *next = row->zsl_h_typec_next;
3569 _db.zsl_h_typec_head = next;
3570 // clear list's tail pointer if list is empty.
3571 if (!next) {
3572 _db.zsl_h_typec_tail = NULL;
3573 }
3574 _db.zsl_h_typec_n--;
3575 row->zsl_h_typec_next = (atf_amc::FTypeC*)-1; // mark as not-in-list
3576 zsl_h_typec_FirstChanged();
3577 }
3578 return row;
3579}
3580
3581// --- atf_amc.FDb.zsl_h_typec.UpdateCycles
3582// Update cycles count from previous clock capture
3583void atf_amc::zsl_h_typec_UpdateCycles() {
3584 u64 cur_cycles = algo::get_cycles();
3585 u64 prev_cycles = algo_lib::_db.clock.value;
3586 ++atf_amc::_db.trace.step_zsl_h_typec;
3587 atf_amc::_db.trace.step_zsl_h_typec_cycles += cur_cycles - prev_cycles;
3588 algo_lib::_db.clock = algo::SchedTime(cur_cycles);
3589}
3590
3591// --- atf_amc.FDb.zs_t_typec.Insert
3592// Insert row into linked list. If row is already in linked list, do nothing.
3593void atf_amc::zs_t_typec_Insert(atf_amc::FTypeC& row) {
3594 if (!zs_t_typec_InLlistQ(row)) {
3595 atf_amc::FTypeC* old_tail = _db.zs_t_typec_tail;
3596 row.zs_t_typec_next = NULL;
3597 _db.zs_t_typec_tail = &row;
3598 atf_amc::FTypeC **new_row_a = &old_tail->zs_t_typec_next;
3599 atf_amc::FTypeC **new_row_b = &_db.zs_t_typec_head;
3600 atf_amc::FTypeC **new_row = old_tail ? new_row_a : new_row_b;
3601 *new_row = &row;
3602 _db.zs_t_typec_n++;
3603 if (_db.zs_t_typec_head == &row) {
3604 zs_t_typec_FirstChanged();
3605 }
3606 }
3607}
3608
3609// --- atf_amc.FDb.zs_t_typec.Remove
3610// Remove element from index. If element is not in index, do nothing.
3611// Since the list is singly-linked, use linear search to locate the element.
3612void atf_amc::zs_t_typec_Remove(atf_amc::FTypeC& row) {
3613 if (zs_t_typec_InLlistQ(row)) {
3614 atf_amc::FTypeC* old_head = _db.zs_t_typec_head;
3615 (void)old_head; // in case it's not used
3616 atf_amc::FTypeC* prev=NULL;
3617 atf_amc::FTypeC* cur = _db.zs_t_typec_head;
3618 while (cur) { // search for element by pointer
3619 atf_amc::FTypeC* next = cur->zs_t_typec_next;
3620 if (cur == &row) {
3621 _db.zs_t_typec_n--; // adjust count
3622
3623 if (!next) {
3624 _db.zs_t_typec_tail = prev; // adjust tail pointer
3625 }
3626 // disconnect element from linked list
3627 if (prev) {
3628 prev->zs_t_typec_next = next;
3629 } else {
3630 _db.zs_t_typec_head = next;
3631 }
3632 row.zs_t_typec_next = (atf_amc::FTypeC*)-1; // not-in-list
3633 break;
3634 }
3635 prev = cur;
3636 cur = next;
3637 }
3638 if (old_head != _db.zs_t_typec_head) {
3639 zs_t_typec_FirstChanged();
3640 }
3641 }
3642}
3643
3644// --- atf_amc.FDb.zs_t_typec.RemoveAll
3645// Empty the index. (The rows are not deleted)
3646void atf_amc::zs_t_typec_RemoveAll() {
3647 atf_amc::FTypeC* row = _db.zs_t_typec_head;
3648 _db.zs_t_typec_head = NULL;
3649 _db.zs_t_typec_tail = NULL;
3650 _db.zs_t_typec_n = 0;
3651 bool do_fire = (NULL != row);
3652 while (row) {
3653 atf_amc::FTypeC* row_next = row->zs_t_typec_next;
3654 row->zs_t_typec_next = (atf_amc::FTypeC*)-1;
3655 row = row_next;
3656 }
3657 if (do_fire) {
3658 zs_t_typec_FirstChanged();
3659 }
3660}
3661
3662// --- atf_amc.FDb.zs_t_typec.RemoveFirst
3663// If linked list is empty, return NULL. Otherwise unlink and return pointer to first element.
3664// Call FirstChanged trigger.
3665atf_amc::FTypeC* atf_amc::zs_t_typec_RemoveFirst() {
3666 atf_amc::FTypeC *row = NULL;
3667 row = _db.zs_t_typec_head;
3668 if (row) {
3669 atf_amc::FTypeC *next = row->zs_t_typec_next;
3670 _db.zs_t_typec_head = next;
3671 // clear list's tail pointer if list is empty.
3672 if (!next) {
3673 _db.zs_t_typec_tail = NULL;
3674 }
3675 _db.zs_t_typec_n--;
3676 row->zs_t_typec_next = (atf_amc::FTypeC*)-1; // mark as not-in-list
3677 zs_t_typec_FirstChanged();
3678 }
3679 return row;
3680}
3681
3682// --- atf_amc.FDb.zs_t_typec.UpdateCycles
3683// Update cycles count from previous clock capture
3684void atf_amc::zs_t_typec_UpdateCycles() {
3685 u64 cur_cycles = algo::get_cycles();
3686 u64 prev_cycles = algo_lib::_db.clock.value;
3687 ++atf_amc::_db.trace.step_zs_t_typec;
3688 atf_amc::_db.trace.step_zs_t_typec_cycles += cur_cycles - prev_cycles;
3689 algo_lib::_db.clock = algo::SchedTime(cur_cycles);
3690}
3691
3692// --- atf_amc.FDb.zs_mt_typec.DestructiveFirst
3693// If index is empty, return NULL
3694// Otherwise return first key in index.
3695// NOTE: this function must be called from the reading thread.
3696// NOTE: if called from the writing thread, it might result in loss of data.
3697atf_amc::FTypeC* atf_amc::zs_mt_typec_DestructiveFirst() {
3698 atf_amc::FTypeC *row = NULL;
3699 row = _db.zs_mt_typec_head;
3700 if (row == NULL && _db.zs_mt_typec_mt != NULL) {
3701 // grab elements from mt-safe portion of the linked list and reverse them.
3702 // due to the above if statement being not quite safe, must check if the fetched
3703 // value is NULL or not.
3704 atf_amc::FTypeC* temp = __sync_lock_test_and_set(&_db.zs_mt_typec_mt, NULL);
3705 if (temp) {
3706 do {
3707 atf_amc::FTypeC* next = temp->zs_mt_typec_next;
3708 temp->zs_mt_typec_next = row;
3709 row = temp;
3710 temp = next;
3711 } while (temp);
3712 }
3713 // update pointer to first element.
3714 _db.zs_mt_typec_head = row;
3715 }
3716 return row;
3717}
3718
3719// --- atf_amc.FDb.zs_mt_typec.Insert
3720// Insert row. Row must not already be in index. If row is already in index, the behavior is undefined.
3721void atf_amc::zs_mt_typec_Insert(atf_amc::FTypeC& row) {
3722 if (!zs_mt_typec_InLlistQ(row)) {
3723 // insertion into thread-safe linked list.
3724 atf_amc::FTypeC *temp = NULL;
3725 atf_amc::FTypeC *oldval = _db.zs_mt_typec_mt;
3726 do {
3727 temp = oldval;
3728 row.zs_mt_typec_next = temp;
3729 oldval = __sync_val_compare_and_swap(&_db.zs_mt_typec_mt, temp, &row);
3730 } while (oldval != temp);
3731 }
3732}
3733
3734// --- atf_amc.FDb.zs_mt_typec.Remove
3735// If element is not in index, do nothing.
3736// Otherwise, throw exception: ZSListMT elements cannot
3737// be removed from the list except via RemoveFIrst.
3738void atf_amc::zs_mt_typec_Remove(atf_amc::FTypeC& row) {
3739 // cannot remove from ZSListMT
3740 // should the process die here?
3741 (void)_db;//only to avoid -Wunused-parameter
3742 (void)row;//only to avoid -Wunused-parameter
3743}
3744
3745// --- atf_amc.FDb.zs_mt_typec.RemoveFirst
3746// If index is empty, return NULL. Otherwise remove and return first key in index.
3747atf_amc::FTypeC* atf_amc::zs_mt_typec_RemoveFirst() {
3748 atf_amc::FTypeC *row = zs_mt_typec_DestructiveFirst();
3749 if (row) {
3750 atf_amc::FTypeC *next = row->zs_mt_typec_next;
3751 _db.zs_mt_typec_head = next;
3752 row->zs_mt_typec_next = (atf_amc::FTypeC*)-1; // mark as not-in-list
3753 }
3754 return row;
3755}
3756
3757// --- atf_amc.FDb.zdl_hnt_typec.Insert
3758// Insert row into linked list. If row is already in linked list, do nothing.
3759void atf_amc::zdl_hnt_typec_Insert(atf_amc::FTypeC& row) {
3760 if (!zdl_hnt_typec_InLlistQ(row)) {
3761 atf_amc::FTypeC* old_head = _db.zdl_hnt_typec_head;
3762 row.zdl_hnt_typec_prev = NULL;
3763 row.zdl_hnt_typec_next = old_head;
3764 _db.zdl_hnt_typec_head = &row;
3765 if (old_head) {
3766 old_head->zdl_hnt_typec_prev = &row;
3767 }
3768 _db.zdl_hnt_typec_n++;
3769 }
3770}
3771
3772// --- atf_amc.FDb.zdl_hnt_typec.Remove
3773// Remove element from index. If element is not in index, do nothing.
3774void atf_amc::zdl_hnt_typec_Remove(atf_amc::FTypeC& row) {
3775 if (zdl_hnt_typec_InLlistQ(row)) {
3776 atf_amc::FTypeC* old_head = _db.zdl_hnt_typec_head;
3777 (void)old_head; // in case it's not used
3778 atf_amc::FTypeC* prev = row.zdl_hnt_typec_prev;
3779 atf_amc::FTypeC* next = row.zdl_hnt_typec_next;
3780 // if element is first, adjust list head; otherwise, adjust previous element's next
3781 atf_amc::FTypeC **new_next_a = &prev->zdl_hnt_typec_next;
3782 atf_amc::FTypeC **new_next_b = &_db.zdl_hnt_typec_head;
3783 atf_amc::FTypeC **new_next = prev ? new_next_a : new_next_b;
3784 *new_next = next;
3785 // if element is not last, adjust next element's prev
3786 if (next != NULL) {
3787 next->zdl_hnt_typec_prev = prev;
3788 }
3789 _db.zdl_hnt_typec_n--;
3790 row.zdl_hnt_typec_next=(atf_amc::FTypeC*)-1; // not-in-list
3791 }
3792}
3793
3794// --- atf_amc.FDb.zdl_hnt_typec.RemoveAll
3795// Empty the index. (The rows are not deleted)
3796void atf_amc::zdl_hnt_typec_RemoveAll() {
3797 atf_amc::FTypeC* row = _db.zdl_hnt_typec_head;
3798 _db.zdl_hnt_typec_head = NULL;
3799 _db.zdl_hnt_typec_n = 0;
3800 while (row) {
3801 atf_amc::FTypeC* row_next = row->zdl_hnt_typec_next;
3802 row->zdl_hnt_typec_next = (atf_amc::FTypeC*)-1;
3803 row->zdl_hnt_typec_prev = NULL;
3804 row = row_next;
3805 }
3806}
3807
3808// --- atf_amc.FDb.zdl_hnt_typec.RemoveFirst
3809// If linked list is empty, return NULL. Otherwise unlink and return pointer to first element.
3810atf_amc::FTypeC* atf_amc::zdl_hnt_typec_RemoveFirst() {
3811 atf_amc::FTypeC *row = NULL;
3812 row = _db.zdl_hnt_typec_head;
3813 if (row) {
3814 atf_amc::FTypeC *next = row->zdl_hnt_typec_next;
3815 _db.zdl_hnt_typec_head = next;
3816 _db.zdl_hnt_typec_n--;
3817 row->zdl_hnt_typec_next = (atf_amc::FTypeC*)-1; // mark as not-in-list
3818 }
3819 return row;
3820}
3821
3822// --- atf_amc.FDb.cdl_h_typec.Insert
3823// Insert row into linked list. If row is already in linked list, do nothing.
3824void atf_amc::cdl_h_typec_Insert(atf_amc::FTypeC& row) {
3825 if (!cdl_h_typec_InLlistQ(row)) {
3826 if (_db.cdl_h_typec_head) {
3827 row.cdl_h_typec_next = _db.cdl_h_typec_head;
3828 row.cdl_h_typec_prev = _db.cdl_h_typec_head->cdl_h_typec_prev;
3829 row.cdl_h_typec_prev->cdl_h_typec_next = &row;
3830 row.cdl_h_typec_next->cdl_h_typec_prev = &row;
3831 _db.cdl_h_typec_head = &row;
3832 } else {
3833 row.cdl_h_typec_next = &row;
3834 row.cdl_h_typec_prev = &row;
3835 _db.cdl_h_typec_head = &row;
3836 }
3837 _db.cdl_h_typec_n++;
3838 }
3839}
3840
3841// --- atf_amc.FDb.cdl_h_typec.Remove
3842// Remove element from index. If element is not in index, do nothing.
3843void atf_amc::cdl_h_typec_Remove(atf_amc::FTypeC& row) {
3844 if (cdl_h_typec_InLlistQ(row)) {
3845 atf_amc::FTypeC* old_head = _db.cdl_h_typec_head;
3846 (void)old_head; // in case it's not used
3847 atf_amc::FTypeC *oldnext = row.cdl_h_typec_next;
3848 atf_amc::FTypeC *oldprev = row.cdl_h_typec_prev;
3849 oldnext->cdl_h_typec_prev = oldprev; // remove element from list
3850 oldprev->cdl_h_typec_next = oldnext;
3851 _db.cdl_h_typec_n--; // adjust count
3852 if (&row == _db.cdl_h_typec_head) {
3853 _db.cdl_h_typec_head = oldnext==&row ? NULL : oldnext; // adjust list head
3854 }
3855 row.cdl_h_typec_next = (atf_amc::FTypeC*)-1; // mark element as not-in-list);
3856 row.cdl_h_typec_prev = NULL; // clear back-pointer
3857 }
3858}
3859
3860// --- atf_amc.FDb.cdl_h_typec.RemoveAll
3861// Empty the index. (The rows are not deleted)
3862void atf_amc::cdl_h_typec_RemoveAll() {
3863 atf_amc::FTypeC* row = _db.cdl_h_typec_head;
3864 atf_amc::FTypeC* head = _db.cdl_h_typec_head;
3865 _db.cdl_h_typec_head = NULL;
3866 _db.cdl_h_typec_n = 0;
3867 while (row) {
3868 atf_amc::FTypeC* row_next = row->cdl_h_typec_next;
3869 row->cdl_h_typec_next = (atf_amc::FTypeC*)-1;
3870 row->cdl_h_typec_prev = NULL;
3871 row = row_next != head ? row_next : NULL;
3872 }
3873}
3874
3875// --- atf_amc.FDb.cdl_h_typec.RemoveFirst
3876// If linked list is empty, return NULL. Otherwise unlink and return pointer to first element.
3877atf_amc::FTypeC* atf_amc::cdl_h_typec_RemoveFirst() {
3878 atf_amc::FTypeC *row = NULL;
3879 row = _db.cdl_h_typec_head;
3880 if (row) {
3881 bool hasmore = row!=row->cdl_h_typec_next;
3882 _db.cdl_h_typec_head = hasmore ? row->cdl_h_typec_next : NULL;
3883 row->cdl_h_typec_next->cdl_h_typec_prev = row->cdl_h_typec_prev;
3884 row->cdl_h_typec_prev->cdl_h_typec_next = row->cdl_h_typec_next;
3885 row->cdl_h_typec_prev = NULL;
3886 _db.cdl_h_typec_n--;
3887 row->cdl_h_typec_next = (atf_amc::FTypeC*)-1; // mark as not-in-list
3888 }
3889 return row;
3890}
3891
3892// --- atf_amc.FDb.cdl_h_typec.RotateFirst
3893// If linked list is empty, return NULL.
3894// Otherwise return head item and advance head to the next item.
3895atf_amc::FTypeC* atf_amc::cdl_h_typec_RotateFirst() {
3896 atf_amc::FTypeC *row = NULL;
3897 row = _db.cdl_h_typec_head;
3898 if (row) {
3899 _db.cdl_h_typec_head = row->cdl_h_typec_next;
3900 }
3901 return row;
3902}
3903
3904// --- atf_amc.FDb.cd_t_typec.Insert
3905// Insert row into linked list. If row is already in linked list, do nothing.
3906void atf_amc::cd_t_typec_Insert(atf_amc::FTypeC& row) {
3907 if (!cd_t_typec_InLlistQ(row)) {
3908 if (_db.cd_t_typec_head) {
3909 row.cd_t_typec_next = _db.cd_t_typec_head;
3910 row.cd_t_typec_prev = _db.cd_t_typec_head->cd_t_typec_prev;
3911 row.cd_t_typec_prev->cd_t_typec_next = &row;
3912 row.cd_t_typec_next->cd_t_typec_prev = &row;
3913 } else {
3914 row.cd_t_typec_next = &row;
3915 row.cd_t_typec_prev = &row;
3916 _db.cd_t_typec_head = &row;
3917 }
3918 _db.cd_t_typec_n++;
3919 }
3920}
3921
3922// --- atf_amc.FDb.cd_t_typec.Remove
3923// Remove element from index. If element is not in index, do nothing.
3924void atf_amc::cd_t_typec_Remove(atf_amc::FTypeC& row) {
3925 if (cd_t_typec_InLlistQ(row)) {
3926 atf_amc::FTypeC* old_head = _db.cd_t_typec_head;
3927 (void)old_head; // in case it's not used
3928 atf_amc::FTypeC *oldnext = row.cd_t_typec_next;
3929 atf_amc::FTypeC *oldprev = row.cd_t_typec_prev;
3930 oldnext->cd_t_typec_prev = oldprev; // remove element from list
3931 oldprev->cd_t_typec_next = oldnext;
3932 _db.cd_t_typec_n--; // adjust count
3933 if (&row == _db.cd_t_typec_head) {
3934 _db.cd_t_typec_head = oldnext==&row ? NULL : oldnext; // adjust list head
3935 }
3936 row.cd_t_typec_next = (atf_amc::FTypeC*)-1; // mark element as not-in-list);
3937 row.cd_t_typec_prev = NULL; // clear back-pointer
3938 }
3939}
3940
3941// --- atf_amc.FDb.cd_t_typec.RemoveAll
3942// Empty the index. (The rows are not deleted)
3943void atf_amc::cd_t_typec_RemoveAll() {
3944 atf_amc::FTypeC* row = _db.cd_t_typec_head;
3945 atf_amc::FTypeC* head = _db.cd_t_typec_head;
3946 _db.cd_t_typec_head = NULL;
3947 _db.cd_t_typec_n = 0;
3948 while (row) {
3949 atf_amc::FTypeC* row_next = row->cd_t_typec_next;
3950 row->cd_t_typec_next = (atf_amc::FTypeC*)-1;
3951 row->cd_t_typec_prev = NULL;
3952 row = row_next != head ? row_next : NULL;
3953 }
3954}
3955
3956// --- atf_amc.FDb.cd_t_typec.RemoveFirst
3957// If linked list is empty, return NULL. Otherwise unlink and return pointer to first element.
3958atf_amc::FTypeC* atf_amc::cd_t_typec_RemoveFirst() {
3959 atf_amc::FTypeC *row = NULL;
3960 row = _db.cd_t_typec_head;
3961 if (row) {
3962 bool hasmore = row!=row->cd_t_typec_next;
3963 _db.cd_t_typec_head = hasmore ? row->cd_t_typec_next : NULL;
3964 row->cd_t_typec_next->cd_t_typec_prev = row->cd_t_typec_prev;
3965 row->cd_t_typec_prev->cd_t_typec_next = row->cd_t_typec_next;
3966 row->cd_t_typec_prev = NULL;
3967 _db.cd_t_typec_n--;
3968 row->cd_t_typec_next = (atf_amc::FTypeC*)-1; // mark as not-in-list
3969 }
3970 return row;
3971}
3972
3973// --- atf_amc.FDb.cd_t_typec.RotateFirst
3974// If linked list is empty, return NULL.
3975// Otherwise return head item and advance head to the next item.
3976atf_amc::FTypeC* atf_amc::cd_t_typec_RotateFirst() {
3977 atf_amc::FTypeC *row = NULL;
3978 row = _db.cd_t_typec_head;
3979 if (row) {
3980 _db.cd_t_typec_head = row->cd_t_typec_next;
3981 }
3982 return row;
3983}
3984
3985// --- atf_amc.FDb.csl_h_typec.Insert
3986// Insert row into linked list. If row is already in linked list, do nothing.
3987void atf_amc::csl_h_typec_Insert(atf_amc::FTypeC& row) {
3988 if (!csl_h_typec_InLlistQ(row)) {
3989 if (_db.csl_h_typec_head) {
3990 row.csl_h_typec_next = _db.csl_h_typec_head;
3991 _db.csl_h_typec_tail->csl_h_typec_next = &row;
3992 _db.csl_h_typec_head = &row;
3993 } else {
3994 row.csl_h_typec_next = &row;
3995 _db.csl_h_typec_head = &row;
3996 _db.csl_h_typec_tail = &row;
3997 }
3998 _db.csl_h_typec_n++;
3999 if (_db.csl_h_typec_head == &row) {
4000 csl_h_typec_FirstChanged();
4001 }
4002 }
4003}
4004
4005// --- atf_amc.FDb.csl_h_typec.Remove
4006// Remove element from index. If element is not in index, do nothing.
4007// Since the list is singly-linked, use linear search to locate the element.
4008void atf_amc::csl_h_typec_Remove(atf_amc::FTypeC& row) {
4009 if (csl_h_typec_InLlistQ(row)) {
4010 atf_amc::FTypeC* old_head = _db.csl_h_typec_head;
4011 (void)old_head; // in case it's not used
4012 atf_amc::FTypeC *oldnext = row.csl_h_typec_next;
4013 // find previous element with linear search -- always scans the entire list
4014 atf_amc::FTypeC *oldprev = row.csl_h_typec_next;
4015 while (oldprev->csl_h_typec_next != &row) {
4016 oldprev = oldprev->csl_h_typec_next;
4017 }
4018 oldprev->csl_h_typec_next = oldnext;
4019 _db.csl_h_typec_n--; // adjust count
4020 if (&row == _db.csl_h_typec_head) {
4021 _db.csl_h_typec_head = oldnext==&row ? NULL : oldnext; // adjust list head
4022 }
4023 if (&row == _db.csl_h_typec_tail) {
4024 _db.csl_h_typec_tail = oldprev==&row ? NULL : oldprev; // adjust list tail
4025 }
4026 row.csl_h_typec_next = (atf_amc::FTypeC*)-1; // mark element as not-in-list);
4027 if (old_head != _db.csl_h_typec_head) {
4028 csl_h_typec_FirstChanged();
4029 }
4030 }
4031}
4032
4033// --- atf_amc.FDb.csl_h_typec.RemoveAll
4034// Empty the index. (The rows are not deleted)
4035void atf_amc::csl_h_typec_RemoveAll() {
4036 atf_amc::FTypeC* row = _db.csl_h_typec_head;
4037 atf_amc::FTypeC* head = _db.csl_h_typec_head;
4038 _db.csl_h_typec_head = NULL;
4039 _db.csl_h_typec_tail = NULL;
4040 _db.csl_h_typec_n = 0;
4041 bool do_fire = (NULL != row);
4042 while (row) {
4043 atf_amc::FTypeC* row_next = row->csl_h_typec_next;
4044 row->csl_h_typec_next = (atf_amc::FTypeC*)-1;
4045 row = row_next != head ? row_next : NULL;
4046 }
4047 if (do_fire) {
4048 csl_h_typec_FirstChanged();
4049 }
4050}
4051
4052// --- atf_amc.FDb.csl_h_typec.RemoveFirst
4053// If linked list is empty, return NULL. Otherwise unlink and return pointer to first element.
4054// Call FirstChanged trigger.
4055atf_amc::FTypeC* atf_amc::csl_h_typec_RemoveFirst() {
4056 atf_amc::FTypeC *row = NULL;
4057 row = _db.csl_h_typec_head;
4058 if (row) {
4059 bool hasmore = row!=row->csl_h_typec_next;
4060 _db.csl_h_typec_head = hasmore ? row->csl_h_typec_next : NULL;
4061 _db.csl_h_typec_tail->csl_h_typec_next = row->csl_h_typec_next;
4062 // clear list's tail pointer if list is empty.
4063 if (!hasmore) {
4064 _db.csl_h_typec_tail = NULL;
4065 }
4066 _db.csl_h_typec_n--;
4067 row->csl_h_typec_next = (atf_amc::FTypeC*)-1; // mark as not-in-list
4068 csl_h_typec_FirstChanged();
4069 }
4070 return row;
4071}
4072
4073// --- atf_amc.FDb.csl_h_typec.RotateFirst
4074// If linked list is empty, return NULL.
4075// Otherwise return head item and advance head to the next item.
4076atf_amc::FTypeC* atf_amc::csl_h_typec_RotateFirst() {
4077 atf_amc::FTypeC *row = NULL;
4078 row = _db.csl_h_typec_head;
4079 if (row) {
4080 _db.csl_h_typec_tail = _db.csl_h_typec_head;
4081 _db.csl_h_typec_head = row->csl_h_typec_next;
4082 }
4083 return row;
4084}
4085
4086// --- atf_amc.FDb.csl_h_typec.UpdateCycles
4087// Update cycles count from previous clock capture
4088void atf_amc::csl_h_typec_UpdateCycles() {
4089 u64 cur_cycles = algo::get_cycles();
4090 u64 prev_cycles = algo_lib::_db.clock.value;
4091 ++atf_amc::_db.trace.step_csl_h_typec;
4092 atf_amc::_db.trace.step_csl_h_typec_cycles += cur_cycles - prev_cycles;
4093 algo_lib::_db.clock = algo::SchedTime(cur_cycles);
4094}
4095
4096// --- atf_amc.FDb.cs_t_typec.Insert
4097// Insert row into linked list. If row is already in linked list, do nothing.
4098void atf_amc::cs_t_typec_Insert(atf_amc::FTypeC& row) {
4099 if (!cs_t_typec_InLlistQ(row)) {
4100 if (_db.cs_t_typec_head) {
4101 row.cs_t_typec_next = _db.cs_t_typec_head;
4102 _db.cs_t_typec_tail->cs_t_typec_next = &row;
4103 _db.cs_t_typec_tail = &row;
4104 } else {
4105 row.cs_t_typec_next = &row;
4106 _db.cs_t_typec_head = &row;
4107 _db.cs_t_typec_tail = &row;
4108 }
4109 _db.cs_t_typec_n++;
4110 if (_db.cs_t_typec_head == &row) {
4111 cs_t_typec_FirstChanged();
4112 }
4113 }
4114}
4115
4116// --- atf_amc.FDb.cs_t_typec.Remove
4117// Remove element from index. If element is not in index, do nothing.
4118// Since the list is singly-linked, use linear search to locate the element.
4119void atf_amc::cs_t_typec_Remove(atf_amc::FTypeC& row) {
4120 if (cs_t_typec_InLlistQ(row)) {
4121 atf_amc::FTypeC* old_head = _db.cs_t_typec_head;
4122 (void)old_head; // in case it's not used
4123 atf_amc::FTypeC *oldnext = row.cs_t_typec_next;
4124 // find previous element with linear search -- always scans the entire list
4125 atf_amc::FTypeC *oldprev = row.cs_t_typec_next;
4126 while (oldprev->cs_t_typec_next != &row) {
4127 oldprev = oldprev->cs_t_typec_next;
4128 }
4129 oldprev->cs_t_typec_next = oldnext;
4130 _db.cs_t_typec_n--; // adjust count
4131 if (&row == _db.cs_t_typec_head) {
4132 _db.cs_t_typec_head = oldnext==&row ? NULL : oldnext; // adjust list head
4133 }
4134 if (&row == _db.cs_t_typec_tail) {
4135 _db.cs_t_typec_tail = oldprev==&row ? NULL : oldprev; // adjust list tail
4136 }
4137 row.cs_t_typec_next = (atf_amc::FTypeC*)-1; // mark element as not-in-list);
4138 if (old_head != _db.cs_t_typec_head) {
4139 cs_t_typec_FirstChanged();
4140 }
4141 }
4142}
4143
4144// --- atf_amc.FDb.cs_t_typec.RemoveAll
4145// Empty the index. (The rows are not deleted)
4146void atf_amc::cs_t_typec_RemoveAll() {
4147 atf_amc::FTypeC* row = _db.cs_t_typec_head;
4148 atf_amc::FTypeC* head = _db.cs_t_typec_head;
4149 _db.cs_t_typec_head = NULL;
4150 _db.cs_t_typec_tail = NULL;
4151 _db.cs_t_typec_n = 0;
4152 bool do_fire = (NULL != row);
4153 while (row) {
4154 atf_amc::FTypeC* row_next = row->cs_t_typec_next;
4155 row->cs_t_typec_next = (atf_amc::FTypeC*)-1;
4156 row = row_next != head ? row_next : NULL;
4157 }
4158 if (do_fire) {
4159 cs_t_typec_FirstChanged();
4160 }
4161}
4162
4163// --- atf_amc.FDb.cs_t_typec.RemoveFirst
4164// If linked list is empty, return NULL. Otherwise unlink and return pointer to first element.
4165// Call FirstChanged trigger.
4166atf_amc::FTypeC* atf_amc::cs_t_typec_RemoveFirst() {
4167 atf_amc::FTypeC *row = NULL;
4168 row = _db.cs_t_typec_head;
4169 if (row) {
4170 bool hasmore = row!=row->cs_t_typec_next;
4171 _db.cs_t_typec_head = hasmore ? row->cs_t_typec_next : NULL;
4172 _db.cs_t_typec_tail->cs_t_typec_next = row->cs_t_typec_next;
4173 // clear list's tail pointer if list is empty.
4174 if (!hasmore) {
4175 _db.cs_t_typec_tail = NULL;
4176 }
4177 _db.cs_t_typec_n--;
4178 row->cs_t_typec_next = (atf_amc::FTypeC*)-1; // mark as not-in-list
4179 cs_t_typec_FirstChanged();
4180 }
4181 return row;
4182}
4183
4184// --- atf_amc.FDb.cs_t_typec.RotateFirst
4185// If linked list is empty, return NULL.
4186// Otherwise return head item and advance head to the next item.
4187atf_amc::FTypeC* atf_amc::cs_t_typec_RotateFirst() {
4188 atf_amc::FTypeC *row = NULL;
4189 row = _db.cs_t_typec_head;
4190 if (row) {
4191 _db.cs_t_typec_tail = _db.cs_t_typec_head;
4192 _db.cs_t_typec_head = row->cs_t_typec_next;
4193 }
4194 return row;
4195}
4196
4197// --- atf_amc.FDb.cs_t_typec.UpdateCycles
4198// Update cycles count from previous clock capture
4199void atf_amc::cs_t_typec_UpdateCycles() {
4200 u64 cur_cycles = algo::get_cycles();
4201 u64 prev_cycles = algo_lib::_db.clock.value;
4202 ++atf_amc::_db.trace.step_cs_t_typec;
4203 atf_amc::_db.trace.step_cs_t_typec_cycles += cur_cycles - prev_cycles;
4204 algo_lib::_db.clock = algo::SchedTime(cur_cycles);
4205}
4206
4207// --- atf_amc.FDb.typea.Alloc
4208// Allocate memory for new default row.
4209// If out of memory, process is killed.
4210atf_amc::FTypeA& atf_amc::typea_Alloc() {
4211 atf_amc::FTypeA* row = typea_AllocMaybe();
4212 if (UNLIKELY(row == NULL)) {
4213 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.FDb.typea comment:'Alloc failed'");
4214 }
4215 return *row;
4216}
4217
4218// --- atf_amc.FDb.typea.AllocMaybe
4219// Allocate memory for new element. If out of memory, return NULL.
4220atf_amc::FTypeA* atf_amc::typea_AllocMaybe() {
4221 atf_amc::FTypeA *row = (atf_amc::FTypeA*)typea_AllocMem();
4222 if (row) {
4223 new (row) atf_amc::FTypeA; // call constructor
4224 row->rowid = i32(typea_N() - 1);
4225 }
4226 return row;
4227}
4228
4229// --- atf_amc.FDb.typea.InsertMaybe
4230// Create new row from struct.
4231// Return pointer to new element, or NULL if insertion failed (due to out-of-memory, duplicate key, etc)
4232atf_amc::FTypeA* atf_amc::typea_InsertMaybe(const atf_amc::TypeA &value) {
4233 atf_amc::FTypeA *row = &typea_Alloc(); // if out of memory, process dies. if input error, return NULL.
4234 typea_CopyIn(*row,const_cast<atf_amc::TypeA&>(value));
4235 bool ok = typea_XrefMaybe(*row); // this may return false
4236 if (!ok) {
4237 typea_RemoveLast(); // delete offending row, any existing xrefs are cleared
4238 row = NULL; // forget this ever happened
4239 }
4240 return row;
4241}
4242
4243// --- atf_amc.FDb.typea.AllocMem
4244// Allocate space for one element. If no memory available, return NULL.
4245void* atf_amc::typea_AllocMem() {
4246 u64 new_nelems = _db.typea_n+1;
4247 // compute level and index on level
4248 u64 bsr = algo::u64_BitScanReverse(new_nelems);
4249 u64 base = u64(1)<<bsr;
4250 u64 index = new_nelems-base;
4251 void *ret = NULL;
4252 // if level doesn't exist yet, create it
4253 atf_amc::FTypeA* lev = NULL;
4254 if (bsr < 32) {
4255 lev = _db.typea_lary[bsr];
4256 if (!lev) {
4257 lev=(atf_amc::FTypeA*)algo_lib::malloc_AllocMem(sizeof(atf_amc::FTypeA) * (u64(1)<<bsr));
4258 _db.typea_lary[bsr] = lev;
4259 }
4260 }
4261 // allocate element from this level
4262 if (lev) {
4263 _db.typea_n = i32(new_nelems);
4264 ret = lev + index;
4265 }
4266 return ret;
4267}
4268
4269// --- atf_amc.FDb.typea.RemoveAll
4270// Remove all elements from Lary
4271void atf_amc::typea_RemoveAll() {
4272 for (u64 n = _db.typea_n; n>0; ) {
4273 n--;
4274 typea_qFind(i32(n)).~FTypeA(); // destroy last element
4275 _db.typea_n = i32(n);
4276 }
4277}
4278
4279// --- atf_amc.FDb.typea.RemoveLast
4280// Delete last element of array. Do nothing if array is empty.
4281void atf_amc::typea_RemoveLast() {
4282 u64 n = _db.typea_n;
4283 if (n > 0) {
4284 n -= 1;
4285 typea_qFind(i32(n)).~FTypeA();
4286 _db.typea_n = i32(n);
4287 }
4288}
4289
4290// --- atf_amc.FDb.typea.XrefMaybe
4291// Insert row into all appropriate indices. If error occurs, store error
4292// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
4293bool atf_amc::typea_XrefMaybe(atf_amc::FTypeA &row) {
4294 bool retval = true;
4295 (void)row;
4296 // insert typea into index ind_typea
4297 if (true) { // user-defined insert condition
4298 bool success = ind_typea_InsertMaybe(row);
4299 if (UNLIKELY(!success)) {
4300 ch_RemoveAll(algo_lib::_db.errtext);
4301 algo_lib::_db.errtext << "atf_amc.duplicate_key xref:atf_amc.FDb.ind_typea"; // check for duplicate key
4302 return false;
4303 }
4304 }
4305 return retval;
4306}
4307
4308// --- atf_amc.FDb.types.Alloc
4309// Allocate memory for new default row.
4310// If out of memory, process is killed.
4311atf_amc::FTypeS& atf_amc::types_Alloc() {
4312 atf_amc::FTypeS* row = types_AllocMaybe();
4313 if (UNLIKELY(row == NULL)) {
4314 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.FDb.types comment:'Alloc failed'");
4315 }
4316 return *row;
4317}
4318
4319// --- atf_amc.FDb.types.AllocMaybe
4320// Allocate memory for new element. If out of memory, return NULL.
4321atf_amc::FTypeS* atf_amc::types_AllocMaybe() {
4322 atf_amc::FTypeS *row = (atf_amc::FTypeS*)types_AllocMem();
4323 if (row) {
4324 new (row) atf_amc::FTypeS; // call constructor
4325 }
4326 return row;
4327}
4328
4329// --- atf_amc.FDb.types.InsertMaybe
4330// Create new row from struct.
4331// Return pointer to new element, or NULL if insertion failed (due to out-of-memory, duplicate key, etc)
4332atf_amc::FTypeS* atf_amc::types_InsertMaybe(const atf_amc::TypeS &value) {
4333 atf_amc::FTypeS *row = &types_Alloc(); // if out of memory, process dies. if input error, return NULL.
4334 types_CopyIn(*row,const_cast<atf_amc::TypeS&>(value));
4335 bool ok = types_XrefMaybe(*row); // this may return false
4336 if (!ok) {
4337 types_RemoveLast(); // delete offending row, any existing xrefs are cleared
4338 row = NULL; // forget this ever happened
4339 }
4340 return row;
4341}
4342
4343// --- atf_amc.FDb.types.AllocMem
4344// Allocate space for one element. If no memory available, return NULL.
4345void* atf_amc::types_AllocMem() {
4346 u64 new_nelems = _db.types_n+1;
4347 // compute level and index on level
4348 u64 bsr = algo::u64_BitScanReverse(new_nelems);
4349 u64 base = u64(1)<<bsr;
4350 u64 index = new_nelems-base;
4351 void *ret = NULL;
4352 // if level doesn't exist yet, create it
4353 atf_amc::FTypeS* lev = NULL;
4354 if (bsr < 32) {
4355 lev = _db.types_lary[bsr];
4356 if (!lev) {
4357 lev=(atf_amc::FTypeS*)algo_lib::malloc_AllocMem(sizeof(atf_amc::FTypeS) * (u64(1)<<bsr));
4358 _db.types_lary[bsr] = lev;
4359 }
4360 }
4361 // allocate element from this level
4362 if (lev) {
4363 _db.types_n = i32(new_nelems);
4364 ret = lev + index;
4365 }
4366 return ret;
4367}
4368
4369// --- atf_amc.FDb.types.RemoveAll
4370// Remove all elements from Lary
4371void atf_amc::types_RemoveAll() {
4372 for (u64 n = _db.types_n; n>0; ) {
4373 n--;
4374 types_qFind(u64(n)).~FTypeS(); // destroy last element
4375 _db.types_n = i32(n);
4376 }
4377}
4378
4379// --- atf_amc.FDb.types.RemoveLast
4380// Delete last element of array. Do nothing if array is empty.
4381void atf_amc::types_RemoveLast() {
4382 u64 n = _db.types_n;
4383 if (n > 0) {
4384 n -= 1;
4385 types_qFind(u64(n)).~FTypeS();
4386 _db.types_n = i32(n);
4387 }
4388}
4389
4390// --- atf_amc.FDb.types.InputMaybe
4391static bool atf_amc::types_InputMaybe(atf_amc::TypeS &elem) {
4392 bool retval = true;
4393 retval = types_InsertMaybe(elem) != nullptr;
4394 return retval;
4395}
4396
4397// --- atf_amc.FDb.types.XrefMaybe
4398// Insert row into all appropriate indices. If error occurs, store error
4399// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
4400bool atf_amc::types_XrefMaybe(atf_amc::FTypeS &row) {
4401 bool retval = true;
4402 (void)row;
4403 // insert types into index ind_types
4404 if (true) { // user-defined insert condition
4405 bool success = ind_types_InsertMaybe(row);
4406 if (UNLIKELY(!success)) {
4407 ch_RemoveAll(algo_lib::_db.errtext);
4408 algo_lib::_db.errtext << "atf_amc.duplicate_key xref:atf_amc.FDb.ind_types"; // check for duplicate key
4409 return false;
4410 }
4411 }
4412 return retval;
4413}
4414
4415// --- atf_amc.FDb.ind_types.Find
4416// Find row by key. Return NULL if not found.
4417atf_amc::FTypeS* atf_amc::ind_types_Find(i32 key) {
4418 u32 index = ::i32_Hash(0, key) & (_db.ind_types_buckets_n - 1);
4419 atf_amc::FTypeS* *e = &_db.ind_types_buckets_elems[index];
4420 atf_amc::FTypeS* ret=NULL;
4421 do {
4422 ret = *e;
4423 bool done = !ret || (*ret).types == key;
4424 if (done) break;
4425 e = &ret->ind_types_next;
4426 } while (true);
4427 return ret;
4428}
4429
4430// --- atf_amc.FDb.ind_types.GetOrCreate
4431// Find row by key. If not found, create and x-reference a new row with with this key.
4432atf_amc::FTypeS& atf_amc::ind_types_GetOrCreate(i32 key) {
4433 atf_amc::FTypeS* ret = ind_types_Find(key);
4434 if (!ret) { // if memory alloc fails, process dies; if insert fails, function returns NULL.
4435 ret = &types_Alloc();
4436 (*ret).types = key;
4437 bool good = types_XrefMaybe(*ret);
4438 if (!good) {
4439 types_RemoveLast(); // delete offending row, any existing xrefs are cleared
4440 ret = NULL;
4441 }
4442 }
4443 vrfy(ret, tempstr() << "atf_amc.create_error table:ind_types key:'"<<key<<"' comment:'bad xref'");
4444 return *ret;
4445}
4446
4447// --- atf_amc.FDb.ind_types.InsertMaybe
4448// Insert row into hash table. Return true if row is reachable through the hash after the function completes.
4449bool atf_amc::ind_types_InsertMaybe(atf_amc::FTypeS& row) {
4450 ind_types_Reserve(1);
4451 bool retval = true; // if already in hash, InsertMaybe returns true
4452 if (LIKELY(row.ind_types_next == (atf_amc::FTypeS*)-1)) {// check if in hash already
4453 u32 index = ::i32_Hash(0, row.types) & (_db.ind_types_buckets_n - 1);
4454 atf_amc::FTypeS* *prev = &_db.ind_types_buckets_elems[index];
4455 do {
4456 atf_amc::FTypeS* ret = *prev;
4457 if (!ret) { // exit condition 1: reached the end of the list
4458 break;
4459 }
4460 if ((*ret).types == row.types) { // exit condition 2: found matching key
4461 retval = false;
4462 break;
4463 }
4464 prev = &ret->ind_types_next;
4465 } while (true);
4466 if (retval) {
4467 row.ind_types_next = *prev;
4468 _db.ind_types_n++;
4469 *prev = &row;
4470 }
4471 }
4472 return retval;
4473}
4474
4475// --- atf_amc.FDb.ind_types.Remove
4476// Remove reference to element from hash index. If element is not in hash, do nothing
4477void atf_amc::ind_types_Remove(atf_amc::FTypeS& row) {
4478 if (LIKELY(row.ind_types_next != (atf_amc::FTypeS*)-1)) {// check if in hash already
4479 u32 index = ::i32_Hash(0, row.types) & (_db.ind_types_buckets_n - 1);
4480 atf_amc::FTypeS* *prev = &_db.ind_types_buckets_elems[index]; // addr of pointer to current element
4481 while (atf_amc::FTypeS *next = *prev) { // scan the collision chain for our element
4482 if (next == &row) { // found it?
4483 *prev = next->ind_types_next; // unlink (singly linked list)
4484 _db.ind_types_n--;
4485 row.ind_types_next = (atf_amc::FTypeS*)-1;// not-in-hash
4486 break;
4487 }
4488 prev = &next->ind_types_next;
4489 }
4490 }
4491}
4492
4493// --- atf_amc.FDb.ind_types.Reserve
4494// Reserve enough room in the hash for N more elements. Return success code.
4495void atf_amc::ind_types_Reserve(int n) {
4496 u32 old_nbuckets = _db.ind_types_buckets_n;
4497 u32 new_nelems = _db.ind_types_n + n;
4498 // # of elements has to be roughly equal to the number of buckets
4499 if (new_nelems > old_nbuckets) {
4500 int new_nbuckets = i32_Max(algo::BumpToPow2(new_nelems), u32(4));
4501 u32 old_size = old_nbuckets * sizeof(atf_amc::FTypeS*);
4502 u32 new_size = new_nbuckets * sizeof(atf_amc::FTypeS*);
4503 // allocate new array. we don't use Realloc since copying is not needed and factor of 2 probably
4504 // means new memory will have to be allocated anyway
4505 atf_amc::FTypeS* *new_buckets = (atf_amc::FTypeS**)algo_lib::malloc_AllocMem(new_size);
4506 if (UNLIKELY(!new_buckets)) {
4507 FatalErrorExit("atf_amc.out_of_memory field:atf_amc.FDb.ind_types");
4508 }
4509 memset(new_buckets, 0, new_size); // clear pointers
4510 // rehash all entries
4511 for (int i = 0; i < _db.ind_types_buckets_n; i++) {
4512 atf_amc::FTypeS* elem = _db.ind_types_buckets_elems[i];
4513 while (elem) {
4514 atf_amc::FTypeS &row = *elem;
4515 atf_amc::FTypeS* next = row.ind_types_next;
4516 u32 index = ::i32_Hash(0, row.types) & (new_nbuckets-1);
4517 row.ind_types_next = new_buckets[index];
4518 new_buckets[index] = &row;
4519 elem = next;
4520 }
4521 }
4522 // free old array
4523 algo_lib::malloc_FreeMem(_db.ind_types_buckets_elems, old_size);
4524 _db.ind_types_buckets_elems = new_buckets;
4525 _db.ind_types_buckets_n = new_nbuckets;
4526 }
4527}
4528
4529// --- atf_amc.FDb.ind_typea.Find
4530// Find row by key. Return NULL if not found.
4531atf_amc::FTypeA* atf_amc::ind_typea_Find(i32 key) {
4532 u32 index = ::i32_Hash(0, key) & (_db.ind_typea_buckets_n - 1);
4533 atf_amc::FTypeA* *e = &_db.ind_typea_buckets_elems[index];
4534 atf_amc::FTypeA* ret=NULL;
4535 do {
4536 ret = *e;
4537 bool done = !ret || (*ret).typea == key;
4538 if (done) break;
4539 e = &ret->ind_typea_next;
4540 } while (true);
4541 return ret;
4542}
4543
4544// --- atf_amc.FDb.ind_typea.GetOrCreate
4545// Find row by key. If not found, create and x-reference a new row with with this key.
4546atf_amc::FTypeA& atf_amc::ind_typea_GetOrCreate(i32 key) {
4547 atf_amc::FTypeA* ret = ind_typea_Find(key);
4548 if (!ret) { // if memory alloc fails, process dies; if insert fails, function returns NULL.
4549 ret = &typea_Alloc();
4550 (*ret).typea = key;
4551 bool good = typea_XrefMaybe(*ret);
4552 if (!good) {
4553 typea_RemoveLast(); // delete offending row, any existing xrefs are cleared
4554 ret = NULL;
4555 }
4556 }
4557 vrfy(ret, tempstr() << "atf_amc.create_error table:ind_typea key:'"<<key<<"' comment:'bad xref'");
4558 return *ret;
4559}
4560
4561// --- atf_amc.FDb.ind_typea.InsertMaybe
4562// Insert row into hash table. Return true if row is reachable through the hash after the function completes.
4563bool atf_amc::ind_typea_InsertMaybe(atf_amc::FTypeA& row) {
4564 ind_typea_Reserve(1);
4565 bool retval = true; // if already in hash, InsertMaybe returns true
4566 if (LIKELY(row.ind_typea_next == (atf_amc::FTypeA*)-1)) {// check if in hash already
4567 u32 index = ::i32_Hash(0, row.typea) & (_db.ind_typea_buckets_n - 1);
4568 atf_amc::FTypeA* *prev = &_db.ind_typea_buckets_elems[index];
4569 do {
4570 atf_amc::FTypeA* ret = *prev;
4571 if (!ret) { // exit condition 1: reached the end of the list
4572 break;
4573 }
4574 if ((*ret).typea == row.typea) { // exit condition 2: found matching key
4575 retval = false;
4576 break;
4577 }
4578 prev = &ret->ind_typea_next;
4579 } while (true);
4580 if (retval) {
4581 row.ind_typea_next = *prev;
4582 _db.ind_typea_n++;
4583 *prev = &row;
4584 }
4585 }
4586 return retval;
4587}
4588
4589// --- atf_amc.FDb.ind_typea.Remove
4590// Remove reference to element from hash index. If element is not in hash, do nothing
4591void atf_amc::ind_typea_Remove(atf_amc::FTypeA& row) {
4592 if (LIKELY(row.ind_typea_next != (atf_amc::FTypeA*)-1)) {// check if in hash already
4593 u32 index = ::i32_Hash(0, row.typea) & (_db.ind_typea_buckets_n - 1);
4594 atf_amc::FTypeA* *prev = &_db.ind_typea_buckets_elems[index]; // addr of pointer to current element
4595 while (atf_amc::FTypeA *next = *prev) { // scan the collision chain for our element
4596 if (next == &row) { // found it?
4597 *prev = next->ind_typea_next; // unlink (singly linked list)
4598 _db.ind_typea_n--;
4599 row.ind_typea_next = (atf_amc::FTypeA*)-1;// not-in-hash
4600 break;
4601 }
4602 prev = &next->ind_typea_next;
4603 }
4604 }
4605}
4606
4607// --- atf_amc.FDb.ind_typea.Reserve
4608// Reserve enough room in the hash for N more elements. Return success code.
4609void atf_amc::ind_typea_Reserve(int n) {
4610 u32 old_nbuckets = _db.ind_typea_buckets_n;
4611 u32 new_nelems = _db.ind_typea_n + n;
4612 // # of elements has to be roughly equal to the number of buckets
4613 if (new_nelems > old_nbuckets) {
4614 int new_nbuckets = i32_Max(algo::BumpToPow2(new_nelems), u32(4));
4615 u32 old_size = old_nbuckets * sizeof(atf_amc::FTypeA*);
4616 u32 new_size = new_nbuckets * sizeof(atf_amc::FTypeA*);
4617 // allocate new array. we don't use Realloc since copying is not needed and factor of 2 probably
4618 // means new memory will have to be allocated anyway
4619 atf_amc::FTypeA* *new_buckets = (atf_amc::FTypeA**)algo_lib::malloc_AllocMem(new_size);
4620 if (UNLIKELY(!new_buckets)) {
4621 FatalErrorExit("atf_amc.out_of_memory field:atf_amc.FDb.ind_typea");
4622 }
4623 memset(new_buckets, 0, new_size); // clear pointers
4624 // rehash all entries
4625 for (int i = 0; i < _db.ind_typea_buckets_n; i++) {
4626 atf_amc::FTypeA* elem = _db.ind_typea_buckets_elems[i];
4627 while (elem) {
4628 atf_amc::FTypeA &row = *elem;
4629 atf_amc::FTypeA* next = row.ind_typea_next;
4630 u32 index = ::i32_Hash(0, row.typea) & (new_nbuckets-1);
4631 row.ind_typea_next = new_buckets[index];
4632 new_buckets[index] = &row;
4633 elem = next;
4634 }
4635 }
4636 // free old array
4637 algo_lib::malloc_FreeMem(_db.ind_typea_buckets_elems, old_size);
4638 _db.ind_typea_buckets_elems = new_buckets;
4639 _db.ind_typea_buckets_n = new_nbuckets;
4640 }
4641}
4642
4643// --- atf_amc.FDb._db.ReadArgv
4644// Read argc,argv directly into the fields of the command line(s)
4645// The following fields are updated:
4646// atf_amc.FDb.cmdline
4647// algo_lib.FDb.cmdline
4648void atf_amc::ReadArgv() {
4649 command::atf_amc &cmd = atf_amc::_db.cmdline;
4650 algo_lib::Cmdline &base = algo_lib::_db.cmdline;
4651 int needarg=-1;// unknown
4652 int argidx=1;// skip process name
4653 int anonidx=0;
4654 algo::strptr nextanon = command::atf_amc_GetAnon(cmd, anonidx);
4655 tempstr err;
4656 algo::strptr attrname;
4657 bool isanon=false; // true if attrname is anonfld (positional)
4658 algo_lib::FieldId baseattrid;
4659 command::FieldId attrid;
4660 bool endopt=false;
4661 int whichns=0;// which namespace does the current attribute belong to
4662 for (; argidx < algo_lib::_db.argc; argidx++) {
4663 algo::strptr arg = algo_lib::_db.argv[argidx];
4664 algo::strptr attrval;
4665 algo::strptr dfltval;
4666 bool haveval=false;
4667 bool dash=elems_N(arg)>1 && arg.elems[0]=='-'; // a single dash is not an option
4668 // this attribute is a value
4669 if (endopt || needarg>0 || !dash) {
4670 attrval=arg;
4671 haveval=true;
4672 } else {
4673 // this attribute is a field name (with - or --)
4674 // or a -- by itself
4675 bool dashdash = elems_N(arg) >= 2 && arg.elems[1]=='-';
4676 int skip = int(dash) + dashdash;
4677 attrname=ch_RestFrom(arg,skip);
4678 if (skip==2 && elems_N(arg)==2) {
4679 endopt=true;
4680 continue;// nothing else to do here
4681 }
4682 // parse "-a:B" arg into attrname,attrvalue
4683 algo::i32_Range colon = TFind(attrname,':');
4684 if (colon.beg < colon.end) {
4685 attrval=ch_RestFrom(attrname,colon.end);
4686 attrname=ch_FirstN(attrname,colon.beg);
4687 haveval=true;
4688 }
4689 // look up which command (this one or the base) contains the field
4690 whichns=0;
4691 needarg=-1;
4692 // look up parameter information in base namespace (needarg will be -1 if lookup fails)
4693 if (algo_lib::FieldId_ReadStrptrMaybe(baseattrid,attrname)) {
4694 needarg = algo_lib::Cmdline_NArgs(baseattrid,dfltval,&isanon);
4695 }
4696 if (needarg<0) {
4697 whichns=1;
4698 // look up parameter information in this namespace (needarg will be -1 if lookup fails)
4699 if (command::FieldId_ReadStrptrMaybe(attrid,attrname)) {
4700 needarg = command::atf_amc_NArgs(attrid,dfltval,&isanon);
4701 }
4702 }
4703 if (attrval == "" && dfltval != "") {
4704 attrval=dfltval;
4705 haveval=true;
4706 }
4707 if (needarg<0) {
4708 err<<"atf_amc: unknown option "<<Keyval("value",arg)<<eol;
4709 } else {
4710 if (isanon) {
4711 if (attrname == nextanon) { // treat named anon (positional) argument as unnamed
4712 attrname = ""; // treat it as unnamed
4713 } else if (nextanon != "") { // disallow out-of-order anon (positional) args
4714 err<<"atf_amc: error at "<<algo::strptr_ToSsim(arg)<<": must be preceded by [-"<<nextanon<<"]"<<eol;
4715 }
4716 }
4717 }
4718 }
4719 // look up anon field name based on index
4720 // anon fields are only allowed in the leaf ns, never base
4721 if (ch_N(attrname) == 0) {
4722 attrname = nextanon;
4723 nextanon = command::atf_amc_GetAnon(cmd, ++anonidx);
4724 command::FieldId_ReadStrptrMaybe(attrid,attrname);
4725 whichns=1;
4726 }
4727 if (ch_N(attrname) == 0) {
4728 err << "atf_amc: too many arguments. error at "<<algo::strptr_ToSsim(arg)<<eol;
4729 }
4730 // read value into currently selected arg
4731 if (haveval) {
4732 bool ret=false;
4733 // it's already known which namespace is consuming the args,
4734 // so directly go there
4735 if (whichns == 0) {
4736 ret=algo_lib::Cmdline_ReadFieldMaybe(base, attrname, attrval);
4737 }
4738 if (whichns==1) {
4739 ret=command::atf_amc_ReadFieldMaybe(cmd, attrname, attrval);
4740 switch(attrid.value) {
4741 default:break;
4742 }
4743 }
4744 if (!ret) {
4745 err<<"atf_amc: error in "
4746 <<Keyval("option",attrname)
4747 <<Keyval("value",attrval)<<eol;
4748 }
4749 needarg--;
4750 if (needarg <= 0) {
4751 attrname="";// forget which argument was being filled
4752 }
4753 }
4754 }
4755 bool dohelp = false;
4756 bool doexit=false;
4757 if (algo_lib::_db.cmdline.help) {
4758 dohelp = true;
4759 doexit = true;
4760 algo_lib::_db.exit_code = 1; // help exits with non-zero status code
4761 } else if (algo_lib::_db.cmdline.version) {
4762 // -ver output goes to stdout
4763 prlog(algo::gitinfo_Get());
4764 doexit = true;
4765 } else if (algo_lib::_db.cmdline.signature) {
4766 ind_beg(algo_lib::_db_dispsigcheck_curs,dispsigcheck,algo_lib::_db) {
4767 // dispsig goes to stdout
4768 dmmeta::Dispsigcheck out;
4769 dispsigcheck_CopyOut(dispsigcheck,out);
4770 prlog(out);
4771 }ind_end
4772 doexit = true;
4773 }
4774 if (!dohelp) {
4775 }
4776 // dmmeta.floadtuples:atf_amc.FDb.cmdline
4777 if (!dohelp && err=="") {
4778 algo_lib::ResetErrtext();
4779 if (!atf_amc::LoadTuplesMaybe(cmd.in,true)) {
4780 err << "atf_amc.load_input "<<algo_lib::DetachBadTags()<<eol;
4781 }
4782 }
4783 if (err != "") {
4784 algo_lib::_db.exit_code=1;
4785 prerr(err);
4786 doexit=true;
4787 }
4788 if (dohelp) {
4789 prlog(atf_amc_help);
4790 }
4791 if (doexit) {
4792 _exit(algo_lib::_db.exit_code);
4793 }
4794 algo_lib::ResetErrtext();
4795}
4796
4797// --- atf_amc.FDb._db.MainLoop
4798// Main loop.
4799void atf_amc::MainLoop() {
4800 algo::SchedTime time(algo::get_cycles());
4801 algo_lib::_db.clock = time;
4802 do {
4803 algo_lib::_db.next_loop.value = algo_lib::_db.limit;
4804 atf_amc::Steps();
4805 } while (algo_lib::_db.next_loop < algo_lib::_db.limit);
4806}
4807
4808// --- atf_amc.FDb._db.Step
4809// Main step
4810void atf_amc::Step() {
4811 bh_typec_Call();
4812 zsl_h_typec_Call();
4813 zs_t_typec_Call();
4814 csl_h_typec_Call();
4815 cs_t_typec_Call();
4816 cd_in_msg_Call();
4817}
4818
4819// --- atf_amc.FDb._db.InitReflection
4820// Load statically available data into tables, register tables and database.
4821static void atf_amc::InitReflection() {
4822 algo_lib::imdb_InsertMaybe(algo::Imdb("atf_amc", atf_amc::InsertStrptrMaybe, atf_amc::Step, atf_amc::MainLoop, NULL, algo::Comment()));
4823
4824 algo::Imtable t_trace;
4825 t_trace.imtable = "atf_amc.trace";
4826 t_trace.ssimfile = "";
4827 t_trace.size = sizeof(atf_amc::trace);
4828 t_trace.comment.value = "";
4829 t_trace.c_RowidFind = trace_RowidFind;
4830 t_trace.NItems = trace_N;
4831 t_trace.Print = (algo::ImrowPrintFcn)atf_amc::trace_Print;
4832 algo_lib::imtable_InsertMaybe(t_trace);
4833
4834
4835 // -- load signatures of existing dispatches --
4836 algo_lib::InsertStrptrMaybe("dmmeta.Dispsigcheck dispsig:'atf_amc.Disp' signature:'d11df8e45dfabb45e515398cd71d30a184879014'");
4837 algo_lib::InsertStrptrMaybe("dmmeta.Dispsigcheck dispsig:'atf_amc.Msgs' signature:'f80a13e46fff2c18de1f4dbbbb11703d07c170d2'");
4838 algo_lib::InsertStrptrMaybe("dmmeta.Dispsigcheck dispsig:'atf_amc.Ssimfiles' signature:'f2409fade5c9373dc13379fe888df9435e3c0987'");
4839 algo_lib::InsertStrptrMaybe("dmmeta.Dispsigcheck dispsig:'atf_amc.Input' signature:'3b9943558be9b03e79fade60297ec50f1d4702a3'");
4840}
4841
4842// --- atf_amc.FDb._db.InsertStrptrMaybe
4843// Parse strptr into known type and add to database.
4844// Return value is true unless an error occurs. If return value is false, algo_lib::_db.errtext has error text
4845bool atf_amc::InsertStrptrMaybe(algo::strptr str) {
4846 bool retval = true;
4847 atf_amc::TableId table_id(-1);
4848 value_SetStrptrMaybe(table_id, algo::GetTypeTag(str));
4849 switch (value_GetEnum(table_id)) {
4850 case atf_amc_TableId_atf_amc_TypeS: { // finput:atf_amc.FDb.types
4851 atf_amc::TypeS elem;
4852 retval = atf_amc::TypeS_ReadStrptrMaybe(elem, str);
4853 retval = retval && types_InputMaybe(elem);
4854 break;
4855 }
4856 case atf_amc_TableId_atf_amc_TypeT: { // finput:atf_amc.FDb.typet
4857 atf_amc::TypeT elem;
4858 retval = atf_amc::TypeT_ReadStrptrMaybe(elem, str);
4859 retval = retval && typet_InputMaybe(elem);
4860 break;
4861 }
4862 default:
4863 break;
4864 } //switch
4865 if (!retval) {
4866 algo_lib::NoteInsertErr(str); // increment error counter
4867 }
4868 return retval;
4869}
4870
4871// --- atf_amc.FDb._db.LoadTuplesMaybe
4872// Load all finputs from given directory.
4873bool atf_amc::LoadTuplesMaybe(algo::strptr root, bool recursive) {
4874 bool retval = true;
4875 if (FileQ(root)) {
4876 retval = atf_amc::LoadTuplesFile(root, recursive);
4877 } else if (root == "-") {
4878 retval = atf_amc::LoadTuplesFd(algo::Fildes(0),"(stdin)",recursive);
4879 } else if (DirectoryQ(root)) {
4880 retval = retval && atf_amc::LoadTuplesFile(algo::SsimFname(root,"dmmeta.dispsigcheck"),recursive);
4881 } else {
4882 algo_lib::SaveBadTag("path", root);
4883 algo_lib::SaveBadTag("comment", "Wrong working directory?");
4884 retval = false;
4885 }
4886 return retval;
4887}
4888
4889// --- atf_amc.FDb._db.LoadTuplesFile
4890// Load all finputs from given file.
4891// Read tuples from file FNAME into this namespace's in-memory database.
4892// If RECURSIVE is TRUE, then also load these tuples into any parent namespaces
4893// It a file referred to by FNAME is missing, no error is reported (it's considered an empty set).
4894// Function returns TRUE if all records were parsed and inserted without error.
4895// If the function returns FALSE, use algo_lib::DetachBadTags() for error description
4896bool atf_amc::LoadTuplesFile(algo::strptr fname, bool recursive) {
4897 bool retval = true;
4898 algo_lib::FFildes fildes;
4899 // missing files are not an error
4900 fildes.fd = OpenRead(fname,algo::FileFlags());
4901 if (ValidQ(fildes.fd)) {
4902 retval = LoadTuplesFd(fildes.fd, fname, recursive);
4903 }
4904 return retval;
4905}
4906
4907// --- atf_amc.FDb._db.LoadTuplesFd
4908// Load all finputs from given file descriptor.
4909bool atf_amc::LoadTuplesFd(algo::Fildes fd, algo::strptr fname, bool recursive) {
4910 bool retval = true;
4911 ind_beg(algo::FileLine_curs,line,fd) {
4912 if (recursive) {
4913 retval = retval && algo_lib::InsertStrptrMaybe(line);
4914 }
4915 retval = retval && atf_amc::InsertStrptrMaybe(line);
4916 if (!retval) {
4917 algo_lib::_db.errtext << eol
4918 << fname << ":"
4919 << (ind_curs(line).i+1)
4920 << ": " << line << eol;
4921 break;
4922 }
4923 }ind_end;
4924 return retval;
4925}
4926
4927// --- atf_amc.FDb._db.LoadSsimfileMaybe
4928// Load specified ssimfile.
4929bool atf_amc::LoadSsimfileMaybe(algo::strptr fname, bool recursive) {
4930 bool retval = true;
4931 if (FileQ(fname)) {
4932 retval = atf_amc::LoadTuplesFile(fname, recursive);
4933 }
4934 return retval;
4935}
4936
4937// --- atf_amc.FDb._db.Steps
4938// Calls Step function of dependencies
4939void atf_amc::Steps() {
4940 atf_amc::Step(); // dependent namespace specified via (dev.targdep)
4941 algo_lib::Step(); // dependent namespace specified via (dev.targdep)
4942}
4943
4944// --- atf_amc.FDb._db.XrefMaybe
4945// Insert row into all appropriate indices. If error occurs, store error
4946// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
4947bool atf_amc::_db_XrefMaybe() {
4948 bool retval = true;
4949 return retval;
4950}
4951
4952// --- atf_amc.FDb.typet.Alloc
4953// Allocate memory for new default row.
4954// If out of memory, process is killed.
4955atf_amc::FTypeT& atf_amc::typet_Alloc() {
4956 atf_amc::FTypeT* row = typet_AllocMaybe();
4957 if (UNLIKELY(row == NULL)) {
4958 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.FDb.typet comment:'Alloc failed'");
4959 }
4960 return *row;
4961}
4962
4963// --- atf_amc.FDb.typet.AllocMaybe
4964// Allocate memory for new element. If out of memory, return NULL.
4965atf_amc::FTypeT* atf_amc::typet_AllocMaybe() {
4966 atf_amc::FTypeT *row = (atf_amc::FTypeT*)typet_AllocMem();
4967 if (row) {
4968 new (row) atf_amc::FTypeT; // call constructor
4969 }
4970 return row;
4971}
4972
4973// --- atf_amc.FDb.typet.InsertMaybe
4974// Create new row from struct.
4975// Return pointer to new element, or NULL if insertion failed (due to out-of-memory, duplicate key, etc)
4976atf_amc::FTypeT* atf_amc::typet_InsertMaybe(const atf_amc::TypeT &value) {
4977 atf_amc::FTypeT *row = &typet_Alloc(); // if out of memory, process dies. if input error, return NULL.
4978 typet_CopyIn(*row,const_cast<atf_amc::TypeT&>(value));
4979 bool ok = typet_XrefMaybe(*row); // this may return false
4980 if (!ok) {
4981 typet_RemoveLast(); // delete offending row, any existing xrefs are cleared
4982 row = NULL; // forget this ever happened
4983 }
4984 return row;
4985}
4986
4987// --- atf_amc.FDb.typet.AllocMem
4988// Allocate space for one element. If no memory available, return NULL.
4989void* atf_amc::typet_AllocMem() {
4990 u64 new_nelems = _db.typet_n+1;
4991 // compute level and index on level
4992 u64 bsr = algo::u64_BitScanReverse(new_nelems);
4993 u64 base = u64(1)<<bsr;
4994 u64 index = new_nelems-base;
4995 void *ret = NULL;
4996 // if level doesn't exist yet, create it
4997 atf_amc::FTypeT* lev = NULL;
4998 if (bsr < 32) {
4999 lev = _db.typet_lary[bsr];
5000 if (!lev) {
5001 lev=(atf_amc::FTypeT*)algo_lib::malloc_AllocMem(sizeof(atf_amc::FTypeT) * (u64(1)<<bsr));
5002 _db.typet_lary[bsr] = lev;
5003 }
5004 }
5005 // allocate element from this level
5006 if (lev) {
5007 _db.typet_n = i32(new_nelems);
5008 ret = lev + index;
5009 }
5010 return ret;
5011}
5012
5013// --- atf_amc.FDb.typet.RemoveAll
5014// Remove all elements from Lary
5015void atf_amc::typet_RemoveAll() {
5016 for (u64 n = _db.typet_n; n>0; ) {
5017 n--;
5018 typet_qFind(u64(n)).~FTypeT(); // destroy last element
5019 _db.typet_n = i32(n);
5020 }
5021}
5022
5023// --- atf_amc.FDb.typet.RemoveLast
5024// Delete last element of array. Do nothing if array is empty.
5025void atf_amc::typet_RemoveLast() {
5026 u64 n = _db.typet_n;
5027 if (n > 0) {
5028 n -= 1;
5029 typet_qFind(u64(n)).~FTypeT();
5030 _db.typet_n = i32(n);
5031 }
5032}
5033
5034// --- atf_amc.FDb.typet.InputMaybe
5035static bool atf_amc::typet_InputMaybe(atf_amc::TypeT &elem) {
5036 bool retval = true;
5037 retval = typet_InsertMaybe(elem) != nullptr;
5038 return retval;
5039}
5040
5041// --- atf_amc.FDb.typet.XrefMaybe
5042// Insert row into all appropriate indices. If error occurs, store error
5043// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
5044bool atf_amc::typet_XrefMaybe(atf_amc::FTypeT &row) {
5045 bool retval = true;
5046 (void)row;
5047 atf_amc::FTypeS* p_types = atf_amc::ind_types_Find(row.types);
5048 if (UNLIKELY(!p_types)) {
5049 algo_lib::ResetErrtext() << "atf_amc.bad_xref index:atf_amc.FDb.ind_types" << Keyval("key", row.types);
5050 return false;
5051 }
5052 // insert typet into index zdl_typet
5053 if (true) { // user-defined insert condition
5054 zdl_typet_Insert(*p_types, row);
5055 }
5056 return retval;
5057}
5058
5059// --- atf_amc.FDb.cstring.Alloc
5060// Allocate memory for new default row.
5061// If out of memory, process is killed.
5062atf_amc::FCstring& atf_amc::cstring_Alloc() {
5063 atf_amc::FCstring* row = cstring_AllocMaybe();
5064 if (UNLIKELY(row == NULL)) {
5065 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.FDb.cstring comment:'Alloc failed'");
5066 }
5067 return *row;
5068}
5069
5070// --- atf_amc.FDb.cstring.AllocMaybe
5071// Allocate memory for new element. If out of memory, return NULL.
5072atf_amc::FCstring* atf_amc::cstring_AllocMaybe() {
5073 atf_amc::FCstring *row = (atf_amc::FCstring*)cstring_AllocMem();
5074 if (row) {
5075 new (row) atf_amc::FCstring; // call constructor
5076 }
5077 return row;
5078}
5079
5080// --- atf_amc.FDb.cstring.InsertMaybe
5081// Create new row from struct.
5082// Return pointer to new element, or NULL if insertion failed (due to out-of-memory, duplicate key, etc)
5083atf_amc::FCstring* atf_amc::cstring_InsertMaybe(const atf_amc::Cstring &value) {
5084 atf_amc::FCstring *row = &cstring_Alloc(); // if out of memory, process dies. if input error, return NULL.
5085 cstring_CopyIn(*row,const_cast<atf_amc::Cstring&>(value));
5086 bool ok = cstring_XrefMaybe(*row); // this may return false
5087 if (!ok) {
5088 cstring_RemoveLast(); // delete offending row, any existing xrefs are cleared
5089 row = NULL; // forget this ever happened
5090 }
5091 return row;
5092}
5093
5094// --- atf_amc.FDb.cstring.AllocMem
5095// Allocate space for one element. If no memory available, return NULL.
5096void* atf_amc::cstring_AllocMem() {
5097 u64 new_nelems = _db.cstring_n+1;
5098 // compute level and index on level
5099 u64 bsr = algo::u64_BitScanReverse(new_nelems);
5100 u64 base = u64(1)<<bsr;
5101 u64 index = new_nelems-base;
5102 void *ret = NULL;
5103 // if level doesn't exist yet, create it
5104 atf_amc::FCstring* lev = NULL;
5105 if (bsr < 32) {
5106 lev = _db.cstring_lary[bsr];
5107 if (!lev) {
5108 lev=(atf_amc::FCstring*)algo_lib::malloc_AllocMem(sizeof(atf_amc::FCstring) * (u64(1)<<bsr));
5109 _db.cstring_lary[bsr] = lev;
5110 }
5111 }
5112 // allocate element from this level
5113 if (lev) {
5114 _db.cstring_n = i32(new_nelems);
5115 ret = lev + index;
5116 }
5117 return ret;
5118}
5119
5120// --- atf_amc.FDb.cstring.RemoveAll
5121// Remove all elements from Lary
5122void atf_amc::cstring_RemoveAll() {
5123 for (u64 n = _db.cstring_n; n>0; ) {
5124 n--;
5125 cstring_qFind(u64(n)).~FCstring(); // destroy last element
5126 _db.cstring_n = i32(n);
5127 }
5128}
5129
5130// --- atf_amc.FDb.cstring.RemoveLast
5131// Delete last element of array. Do nothing if array is empty.
5132void atf_amc::cstring_RemoveLast() {
5133 u64 n = _db.cstring_n;
5134 if (n > 0) {
5135 n -= 1;
5136 cstring_qFind(u64(n)).~FCstring();
5137 _db.cstring_n = i32(n);
5138 }
5139}
5140
5141// --- atf_amc.FDb.cstring.XrefMaybe
5142// Insert row into all appropriate indices. If error occurs, store error
5143// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
5144bool atf_amc::cstring_XrefMaybe(atf_amc::FCstring &row) {
5145 bool retval = true;
5146 (void)row;
5147 // insert cstring into index ind_cstring
5148 if (true) { // user-defined insert condition
5149 bool success = ind_cstring_InsertMaybe(row);
5150 if (UNLIKELY(!success)) {
5151 ch_RemoveAll(algo_lib::_db.errtext);
5152 algo_lib::_db.errtext << "atf_amc.duplicate_key xref:atf_amc.FDb.ind_cstring"; // check for duplicate key
5153 return false;
5154 }
5155 }
5156 return retval;
5157}
5158
5159// --- atf_amc.FDb.ind_cstring.Find
5160// Find row by key. Return NULL if not found.
5161atf_amc::FCstring* atf_amc::ind_cstring_Find(const algo::strptr& key) {
5162 u32 index = algo::cstring_Hash(0, key) & (_db.ind_cstring_buckets_n - 1);
5163 atf_amc::FCstring* *e = &_db.ind_cstring_buckets_elems[index];
5164 atf_amc::FCstring* ret=NULL;
5165 do {
5166 ret = *e;
5167 bool done = !ret || (*ret).str == key;
5168 if (done) break;
5169 e = &ret->ind_cstring_next;
5170 } while (true);
5171 return ret;
5172}
5173
5174// --- atf_amc.FDb.ind_cstring.GetOrCreate
5175// Find row by key. If not found, create and x-reference a new row with with this key.
5176atf_amc::FCstring& atf_amc::ind_cstring_GetOrCreate(const algo::strptr& key) {
5177 atf_amc::FCstring* ret = ind_cstring_Find(key);
5178 if (!ret) { // if memory alloc fails, process dies; if insert fails, function returns NULL.
5179 ret = &cstring_Alloc();
5180 (*ret).str = key;
5181 bool good = cstring_XrefMaybe(*ret);
5182 if (!good) {
5183 cstring_RemoveLast(); // delete offending row, any existing xrefs are cleared
5184 ret = NULL;
5185 }
5186 }
5187 vrfy(ret, tempstr() << "atf_amc.create_error table:ind_cstring key:'"<<key<<"' comment:'bad xref'");
5188 return *ret;
5189}
5190
5191// --- atf_amc.FDb.ind_cstring.InsertMaybe
5192// Insert row into hash table. Return true if row is reachable through the hash after the function completes.
5193bool atf_amc::ind_cstring_InsertMaybe(atf_amc::FCstring& row) {
5194 ind_cstring_Reserve(1);
5195 bool retval = true; // if already in hash, InsertMaybe returns true
5196 if (LIKELY(row.ind_cstring_next == (atf_amc::FCstring*)-1)) {// check if in hash already
5197 u32 index = algo::cstring_Hash(0, row.str) & (_db.ind_cstring_buckets_n - 1);
5198 atf_amc::FCstring* *prev = &_db.ind_cstring_buckets_elems[index];
5199 do {
5200 atf_amc::FCstring* ret = *prev;
5201 if (!ret) { // exit condition 1: reached the end of the list
5202 break;
5203 }
5204 if ((*ret).str == row.str) { // exit condition 2: found matching key
5205 retval = false;
5206 break;
5207 }
5208 prev = &ret->ind_cstring_next;
5209 } while (true);
5210 if (retval) {
5211 row.ind_cstring_next = *prev;
5212 _db.ind_cstring_n++;
5213 *prev = &row;
5214 }
5215 }
5216 return retval;
5217}
5218
5219// --- atf_amc.FDb.ind_cstring.Remove
5220// Remove reference to element from hash index. If element is not in hash, do nothing
5221void atf_amc::ind_cstring_Remove(atf_amc::FCstring& row) {
5222 if (LIKELY(row.ind_cstring_next != (atf_amc::FCstring*)-1)) {// check if in hash already
5223 u32 index = algo::cstring_Hash(0, row.str) & (_db.ind_cstring_buckets_n - 1);
5224 atf_amc::FCstring* *prev = &_db.ind_cstring_buckets_elems[index]; // addr of pointer to current element
5225 while (atf_amc::FCstring *next = *prev) { // scan the collision chain for our element
5226 if (next == &row) { // found it?
5227 *prev = next->ind_cstring_next; // unlink (singly linked list)
5228 _db.ind_cstring_n--;
5229 row.ind_cstring_next = (atf_amc::FCstring*)-1;// not-in-hash
5230 break;
5231 }
5232 prev = &next->ind_cstring_next;
5233 }
5234 }
5235}
5236
5237// --- atf_amc.FDb.ind_cstring.Reserve
5238// Reserve enough room in the hash for N more elements. Return success code.
5239void atf_amc::ind_cstring_Reserve(int n) {
5240 u32 old_nbuckets = _db.ind_cstring_buckets_n;
5241 u32 new_nelems = _db.ind_cstring_n + n;
5242 // # of elements has to be roughly equal to the number of buckets
5243 if (new_nelems > old_nbuckets) {
5244 int new_nbuckets = i32_Max(algo::BumpToPow2(new_nelems), u32(4));
5245 u32 old_size = old_nbuckets * sizeof(atf_amc::FCstring*);
5246 u32 new_size = new_nbuckets * sizeof(atf_amc::FCstring*);
5247 // allocate new array. we don't use Realloc since copying is not needed and factor of 2 probably
5248 // means new memory will have to be allocated anyway
5249 atf_amc::FCstring* *new_buckets = (atf_amc::FCstring**)algo_lib::malloc_AllocMem(new_size);
5250 if (UNLIKELY(!new_buckets)) {
5251 FatalErrorExit("atf_amc.out_of_memory field:atf_amc.FDb.ind_cstring");
5252 }
5253 memset(new_buckets, 0, new_size); // clear pointers
5254 // rehash all entries
5255 for (int i = 0; i < _db.ind_cstring_buckets_n; i++) {
5256 atf_amc::FCstring* elem = _db.ind_cstring_buckets_elems[i];
5257 while (elem) {
5258 atf_amc::FCstring &row = *elem;
5259 atf_amc::FCstring* next = row.ind_cstring_next;
5260 u32 index = algo::cstring_Hash(0, row.str) & (new_nbuckets-1);
5261 row.ind_cstring_next = new_buckets[index];
5262 new_buckets[index] = &row;
5263 elem = next;
5264 }
5265 }
5266 // free old array
5267 algo_lib::malloc_FreeMem(_db.ind_cstring_buckets_elems, old_size);
5268 _db.ind_cstring_buckets_elems = new_buckets;
5269 _db.ind_cstring_buckets_n = new_nbuckets;
5270 }
5271}
5272
5273// --- atf_amc.FDb.msgbuf.XrefMaybe
5274// Insert row into all appropriate indices. If error occurs, store error
5275// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
5276bool atf_amc::msgbuf_XrefMaybe(atf_amc::Msgbuf &row) {
5277 bool retval = true;
5278 (void)row;
5279 return retval;
5280}
5281
5282// --- atf_amc.FDb.bytebuf.XrefMaybe
5283// Insert row into all appropriate indices. If error occurs, store error
5284// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
5285bool atf_amc::bytebuf_XrefMaybe(atf_amc::Bytebuf &row) {
5286 bool retval = true;
5287 (void)row;
5288 return retval;
5289}
5290
5291// --- atf_amc.FDb.linebuf.XrefMaybe
5292// Insert row into all appropriate indices. If error occurs, store error
5293// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
5294bool atf_amc::linebuf_XrefMaybe(atf_amc::Linebuf &row) {
5295 bool retval = true;
5296 (void)row;
5297 return retval;
5298}
5299
5300// --- atf_amc.FDb.cd_in_msg.Insert
5301// Insert row into linked list. If row is already in linked list, do nothing.
5302void atf_amc::cd_in_msg_Insert(atf_amc::Msgbuf& row) {
5303 if (!cd_in_msg_InLlistQ(row)) {
5304 if (_db.cd_in_msg_head) {
5305 row.cd_in_msg_next = _db.cd_in_msg_head;
5306 row.cd_in_msg_prev = _db.cd_in_msg_head->cd_in_msg_prev;
5307 row.cd_in_msg_prev->cd_in_msg_next = &row;
5308 row.cd_in_msg_next->cd_in_msg_prev = &row;
5309 } else {
5310 row.cd_in_msg_next = &row;
5311 row.cd_in_msg_prev = &row;
5312 _db.cd_in_msg_head = &row;
5313 }
5314 if (_db.cd_in_msg_head == &row) {
5315 cd_in_msg_FirstChanged();
5316 }
5317 }
5318}
5319
5320// --- atf_amc.FDb.cd_in_msg.Remove
5321// Remove element from index. If element is not in index, do nothing.
5322void atf_amc::cd_in_msg_Remove(atf_amc::Msgbuf& row) {
5323 if (cd_in_msg_InLlistQ(row)) {
5324 atf_amc::Msgbuf* old_head = _db.cd_in_msg_head;
5325 (void)old_head; // in case it's not used
5326 atf_amc::Msgbuf *oldnext = row.cd_in_msg_next;
5327 atf_amc::Msgbuf *oldprev = row.cd_in_msg_prev;
5328 oldnext->cd_in_msg_prev = oldprev; // remove element from list
5329 oldprev->cd_in_msg_next = oldnext;
5330 if (&row == _db.cd_in_msg_head) {
5331 _db.cd_in_msg_head = oldnext==&row ? NULL : oldnext; // adjust list head
5332 }
5333 row.cd_in_msg_next = (atf_amc::Msgbuf*)-1; // mark element as not-in-list);
5334 row.cd_in_msg_prev = NULL; // clear back-pointer
5335 if (old_head != _db.cd_in_msg_head) {
5336 cd_in_msg_FirstChanged();
5337 }
5338 }
5339}
5340
5341// --- atf_amc.FDb.cd_in_msg.RemoveAll
5342// Empty the index. (The rows are not deleted)
5343void atf_amc::cd_in_msg_RemoveAll() {
5344 atf_amc::Msgbuf* row = _db.cd_in_msg_head;
5345 atf_amc::Msgbuf* head = _db.cd_in_msg_head;
5346 _db.cd_in_msg_head = NULL;
5347 bool do_fire = (NULL != row);
5348 while (row) {
5349 atf_amc::Msgbuf* row_next = row->cd_in_msg_next;
5350 row->cd_in_msg_next = (atf_amc::Msgbuf*)-1;
5351 row->cd_in_msg_prev = NULL;
5352 row = row_next != head ? row_next : NULL;
5353 }
5354 if (do_fire) {
5355 cd_in_msg_FirstChanged();
5356 }
5357}
5358
5359// --- atf_amc.FDb.cd_in_msg.RemoveFirst
5360// If linked list is empty, return NULL. Otherwise unlink and return pointer to first element.
5361// Call FirstChanged trigger.
5362atf_amc::Msgbuf* atf_amc::cd_in_msg_RemoveFirst() {
5363 atf_amc::Msgbuf *row = NULL;
5364 row = _db.cd_in_msg_head;
5365 if (row) {
5366 bool hasmore = row!=row->cd_in_msg_next;
5367 _db.cd_in_msg_head = hasmore ? row->cd_in_msg_next : NULL;
5368 row->cd_in_msg_next->cd_in_msg_prev = row->cd_in_msg_prev;
5369 row->cd_in_msg_prev->cd_in_msg_next = row->cd_in_msg_next;
5370 row->cd_in_msg_prev = NULL;
5371 row->cd_in_msg_next = (atf_amc::Msgbuf*)-1; // mark as not-in-list
5372 cd_in_msg_FirstChanged();
5373 }
5374 return row;
5375}
5376
5377// --- atf_amc.FDb.cd_in_msg.RotateFirst
5378// If linked list is empty, return NULL.
5379// Otherwise return head item and advance head to the next item.
5380atf_amc::Msgbuf* atf_amc::cd_in_msg_RotateFirst() {
5381 atf_amc::Msgbuf *row = NULL;
5382 row = _db.cd_in_msg_head;
5383 if (row) {
5384 _db.cd_in_msg_head = row->cd_in_msg_next;
5385 }
5386 return row;
5387}
5388
5389// --- atf_amc.FDb.cd_in_msg.FirstChanged
5390// First element of index changed.
5391static void atf_amc::cd_in_msg_FirstChanged() {
5392}
5393
5394// --- atf_amc.FDb.cd_in_msg.UpdateCycles
5395// Update cycles count from previous clock capture
5396inline static void atf_amc::cd_in_msg_UpdateCycles() {
5397 u64 cur_cycles = algo::get_cycles();
5398 u64 prev_cycles = algo_lib::_db.clock.value;
5399 ++atf_amc::_db.trace.step_cd_in_msg;
5400 atf_amc::_db.trace.step_cd_in_msg_cycles += cur_cycles - prev_cycles;
5401 algo_lib::_db.clock = algo::SchedTime(cur_cycles);
5402}
5403
5404// --- atf_amc.FDb.cd_in_msg.Call
5405inline static void atf_amc::cd_in_msg_Call() {
5406 if (!atf_amc::cd_in_msg_EmptyQ()) { // fstep:atf_amc.FDb.cd_in_msg
5407 atf_amc::cd_in_msg_Step(); // steptype:Inline: call function on every step
5408 cd_in_msg_UpdateCycles();
5409 algo_lib::_db.next_loop = algo_lib::_db.clock;
5410 }
5411}
5412
5413// --- atf_amc.FDb.typeb.Alloc
5414// Allocate memory for new default row.
5415// If out of memory, process is killed.
5416atf_amc::FTypeB& atf_amc::typeb_Alloc() {
5417 atf_amc::FTypeB* row = typeb_AllocMaybe();
5418 if (UNLIKELY(row == NULL)) {
5419 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.FDb.typeb comment:'Alloc failed'");
5420 }
5421 return *row;
5422}
5423
5424// --- atf_amc.FDb.typeb.AllocMaybe
5425// Allocate memory for new element. If out of memory, return NULL.
5426atf_amc::FTypeB* atf_amc::typeb_AllocMaybe() {
5427 atf_amc::FTypeB *row = (atf_amc::FTypeB*)typeb_AllocMem();
5428 if (row) {
5429 new (row) atf_amc::FTypeB; // call constructor
5430 }
5431 return row;
5432}
5433
5434// --- atf_amc.FDb.typeb.InsertMaybe
5435// Create new row from struct.
5436// Return pointer to new element, or NULL if insertion failed (due to out-of-memory, duplicate key, etc)
5437atf_amc::FTypeB* atf_amc::typeb_InsertMaybe(const atf_amc::TypeB &value) {
5438 atf_amc::FTypeB *row = &typeb_Alloc(); // if out of memory, process dies. if input error, return NULL.
5439 typeb_CopyIn(*row,const_cast<atf_amc::TypeB&>(value));
5440 bool ok = typeb_XrefMaybe(*row); // this may return false
5441 if (!ok) {
5442 typeb_Delete(*row); // delete offending row, any existing xrefs are cleared
5443 row = NULL; // forget this ever happened
5444 }
5445 return row;
5446}
5447
5448// --- atf_amc.FDb.typeb.Delete
5449// Remove row from all global and cross indices, then deallocate row
5450void atf_amc::typeb_Delete(atf_amc::FTypeB &row) {
5451 row.~FTypeB();
5452 typeb_FreeMem(row);
5453}
5454
5455// --- atf_amc.FDb.typeb.AllocMem
5456// Allocate space for one element
5457// If no memory available, return NULL.
5458void* atf_amc::typeb_AllocMem() {
5459 atf_amc::FTypeB *row = _db.typeb_free;
5460 if (UNLIKELY(!row)) {
5461 typeb_Reserve(1);
5462 row = _db.typeb_free;
5463 }
5464 if (row) {
5465 _db.typeb_free = row->typeb_next;
5466 }
5467 return row;
5468}
5469
5470// --- atf_amc.FDb.typeb.FreeMem
5471// Remove mem from all global and cross indices, then deallocate mem
5472void atf_amc::typeb_FreeMem(atf_amc::FTypeB &row) {
5473 if (UNLIKELY(row.typeb_next != (atf_amc::FTypeB*)-1)) {
5474 FatalErrorExit("atf_amc.tpool_double_delete pool:atf_amc.FDb.typeb comment:'double deletion caught'");
5475 }
5476 row.typeb_next = _db.typeb_free; // insert into free list
5477 _db.typeb_free = &row;
5478}
5479
5480// --- atf_amc.FDb.typeb.Reserve
5481// Preallocate memory for N more elements
5482// Return number of elements actually reserved.
5483u64 atf_amc::typeb_Reserve(u64 n_elems) {
5484 u64 ret = 0;
5485 while (ret < n_elems) {
5486 u64 size = _db.typeb_blocksize; // underlying allocator is probably Lpool
5487 u64 reserved = typeb_ReserveMem(size);
5488 ret += reserved;
5489 if (reserved == 0) {
5490 break;
5491 }
5492 }
5493 return ret;
5494}
5495
5496// --- atf_amc.FDb.typeb.ReserveMem
5497// Allocate block of given size, break up into small elements and append to free list.
5498// Return number of elements reserved.
5499u64 atf_amc::typeb_ReserveMem(u64 size) {
5500 u64 ret = 0;
5501 if (size >= sizeof(atf_amc::FTypeB)) {
5502 atf_amc::FTypeB *mem = (atf_amc::FTypeB*)algo_lib::malloc_AllocMem(size);
5503 ret = mem ? size / sizeof(atf_amc::FTypeB) : 0;
5504 // add newly allocated elements to the free list;
5505 for (u64 i=0; i < ret; i++) {
5506 mem[i].typeb_next = _db.typeb_free;
5507 _db.typeb_free = mem+i;
5508 }
5509 }
5510 return ret;
5511}
5512
5513// --- atf_amc.FDb.typeb.XrefMaybe
5514// Insert row into all appropriate indices. If error occurs, store error
5515// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
5516bool atf_amc::typeb_XrefMaybe(atf_amc::FTypeB &row) {
5517 bool retval = true;
5518 (void)row;
5519 atf_amc::FTypeA* p_typea = atf_amc::ind_typea_Find(row.typea);
5520 if (UNLIKELY(!p_typea)) {
5521 algo_lib::ResetErrtext() << "atf_amc.bad_xref index:atf_amc.FDb.ind_typea" << Keyval("key", row.typea);
5522 return false;
5523 }
5524 // insert typeb into index zdl_typeb
5525 if (true) { // user-defined insert condition
5526 zdl_typeb_Insert(*p_typea, row);
5527 }
5528 return retval;
5529}
5530
5531// --- atf_amc.FDb.pooledbe64.Alloc
5532// Allocate memory for new default row.
5533// If out of memory, process is killed.
5534atf_amc::PooledBE64& atf_amc::pooledbe64_Alloc() {
5535 atf_amc::PooledBE64* row = pooledbe64_AllocMaybe();
5536 if (UNLIKELY(row == NULL)) {
5537 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.FDb.pooledbe64 comment:'Alloc failed'");
5538 }
5539 return *row;
5540}
5541
5542// --- atf_amc.FDb.pooledbe64.AllocMaybe
5543// Allocate memory for new element. If out of memory, return NULL.
5544atf_amc::PooledBE64* atf_amc::pooledbe64_AllocMaybe() {
5545 atf_amc::PooledBE64 *row = (atf_amc::PooledBE64*)pooledbe64_AllocMem();
5546 if (row) {
5547 new (row) atf_amc::PooledBE64; // call constructor
5548 }
5549 return row;
5550}
5551
5552// --- atf_amc.FDb.pooledbe64.Delete
5553// Remove row from all global and cross indices, then deallocate row
5554void atf_amc::pooledbe64_Delete(atf_amc::PooledBE64 &row) {
5555 row.~PooledBE64();
5556 pooledbe64_FreeMem(row);
5557}
5558
5559// --- atf_amc.FDb.pooledbe64.AllocMem
5560// Allocate space for one element
5561// If no memory available, return NULL.
5562void* atf_amc::pooledbe64_AllocMem() {
5563 atf_amc::PooledBE64 *row = _db.pooledbe64_free;
5564 if (UNLIKELY(!row)) {
5565 pooledbe64_Reserve(1);
5566 row = _db.pooledbe64_free;
5567 }
5568 if (row) {
5569 _db.pooledbe64_free = row->pooledbe64_next;
5570 }
5571 return row;
5572}
5573
5574// --- atf_amc.FDb.pooledbe64.FreeMem
5575// Remove mem from all global and cross indices, then deallocate mem
5576void atf_amc::pooledbe64_FreeMem(atf_amc::PooledBE64 &row) {
5577 if (UNLIKELY(row.pooledbe64_next != (atf_amc::PooledBE64*)-1)) {
5578 FatalErrorExit("atf_amc.tpool_double_delete pool:atf_amc.FDb.pooledbe64 comment:'double deletion caught'");
5579 }
5580 row.pooledbe64_next = _db.pooledbe64_free; // insert into free list
5581 _db.pooledbe64_free = &row;
5582}
5583
5584// --- atf_amc.FDb.pooledbe64.Reserve
5585// Preallocate memory for N more elements
5586// Return number of elements actually reserved.
5587u64 atf_amc::pooledbe64_Reserve(u64 n_elems) {
5588 u64 ret = 0;
5589 while (ret < n_elems) {
5590 u64 size = _db.pooledbe64_blocksize; // underlying allocator is probably Lpool
5591 u64 reserved = pooledbe64_ReserveMem(size);
5592 ret += reserved;
5593 if (reserved == 0) {
5594 break;
5595 }
5596 }
5597 return ret;
5598}
5599
5600// --- atf_amc.FDb.pooledbe64.ReserveMem
5601// Allocate block of given size, break up into small elements and append to free list.
5602// Return number of elements reserved.
5603u64 atf_amc::pooledbe64_ReserveMem(u64 size) {
5604 u64 ret = 0;
5605 if (size >= sizeof(atf_amc::PooledBE64)) {
5606 atf_amc::PooledBE64 *mem = (atf_amc::PooledBE64*)algo_lib::malloc_AllocMem(size);
5607 ret = mem ? size / sizeof(atf_amc::PooledBE64) : 0;
5608 // add newly allocated elements to the free list;
5609 for (u64 i=0; i < ret; i++) {
5610 mem[i].pooledbe64_next = _db.pooledbe64_free;
5611 _db.pooledbe64_free = mem+i;
5612 }
5613 }
5614 return ret;
5615}
5616
5617// --- atf_amc.FDb.pooledbe64.XrefMaybe
5618// Insert row into all appropriate indices. If error occurs, store error
5619// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
5620bool atf_amc::pooledbe64_XrefMaybe(atf_amc::PooledBE64 &row) {
5621 bool retval = true;
5622 (void)row;
5623 return retval;
5624}
5625
5626// --- atf_amc.FDb.varlen_extern.FreeMem
5627// Free block of memory previously returned by Lpool.
5628void atf_amc::varlen_extern_FreeMem(void* mem, u64 size) {
5629 size = u64_Max(size,1ULL<<4);
5630 u64 cell = algo::u64_BitScanReverse(size-1) + 1 - 4;
5631 if (mem && cell < 36) {
5632 varlen_extern_Lpblock *temp = (varlen_extern_Lpblock*)mem; // push singly linked list
5633 temp->next = _db.varlen_extern_free[cell];
5634 _db.varlen_extern_free[cell] = temp;
5635 _db.varlen_extern_n--;
5636 }
5637}
5638
5639// --- atf_amc.FDb.varlen_extern.AllocMem
5640// Allocate new piece of memory at least SIZE bytes long.
5641// If not successful, return NULL
5642// The allocated block is at least 1<<4
5643// The maximum allocation size is at most 1<<(36+4)
5644void* atf_amc::varlen_extern_AllocMem(u64 size) {
5645 void *retval = NULL;
5646 size = u64_Max(size,1<<4); // enforce alignment
5647 u64 cell = algo::u64_BitScanReverse(size-1) + 1 - 4;
5648 if (cell < 36) {
5649 u64 i = cell;
5650 // try to find a block that's at least as large as required.
5651 // if found, remove from free list
5652 for (; i < 36; i++) {
5653 varlen_extern_Lpblock *blk = _db.varlen_extern_free[i];
5654 if (blk) {
5655 _db.varlen_extern_free[i] = blk->next;
5656 retval = blk;
5657 break;
5658 }
5659 }
5660 // if suitable size block is not found, create a new one
5661 // by requesting a block from the base allocator.
5662 if (UNLIKELY(!retval)) {
5663 i = u64_Max(cell, 21-4); // 2MB min -- allow huge page to be used
5664 retval = algo_lib::malloc_AllocMem(1ULL<<(i+4));
5665 }
5666 if (LIKELY(retval)) {
5667 // if block is more than 2x as large as needed, return the upper half to the free
5668 // list (repeatedly). meanwhile, retval doesn't change.
5669 while (i > cell) {
5670 i--;
5671 int half = 1ULL<<(i+4);
5672 varlen_extern_Lpblock *blk = (varlen_extern_Lpblock*)((u8*)retval + half);
5673 blk->next = _db.varlen_extern_free[i];
5674 _db.varlen_extern_free[i] = blk;
5675 }
5676 }
5677 _db.varlen_extern_n += retval != NULL;
5678 }
5679 return retval;
5680}
5681
5682// --- atf_amc.FDb.varlen_extern.ReserveBuffers
5683// Add N buffers of some size to the free store
5684// Reserve NBUF buffers of size BUFSIZE from the base pool (algo_lib::malloc)
5685bool atf_amc::varlen_extern_ReserveBuffers(u64 nbuf, u64 bufsize) {
5686 bool retval = true;
5687 bufsize = u64_Max(bufsize, 1<<4);
5688 u64 cell = algo::u64_BitScanReverse(bufsize-1) + 1 - 4;
5689 if (cell < 36) {
5690 for (u64 i = 0; i < nbuf; i++) {
5691 u64 size = 1ULL<<(cell+4);
5692 varlen_extern_Lpblock *temp = (varlen_extern_Lpblock*)algo_lib::malloc_AllocMem(size);
5693 if (temp == NULL) {
5694 retval = false;
5695 break;// why continue?
5696 } else {
5697 temp->next = _db.varlen_extern_free[cell];
5698 _db.varlen_extern_free[cell] = temp;
5699 }
5700 }
5701 }
5702 return retval;
5703}
5704
5705// --- atf_amc.FDb.varlen_extern.ReallocMem
5706// Allocate new block, copy old to new, delete old.
5707// If the new size is same as old size, do nothing.
5708// In all other cases, new memory is allocated (i.e. size reduction is not a no-op)
5709// If no memory, return NULL; old memory remains untouched
5710void* atf_amc::varlen_extern_ReallocMem(void* oldmem, u64 old_size, u64 new_size) {
5711 void *ret = oldmem;
5712 if (new_size != old_size) {
5713 ret = varlen_extern_AllocMem(new_size);
5714 if (ret && oldmem) {
5715 memcpy(ret,oldmem,u64_Min(new_size,old_size));
5716 varlen_extern_FreeMem(oldmem, old_size);
5717 }
5718 }
5719 return ret;
5720}
5721
5722// --- atf_amc.FDb.varlen_extern.Alloc
5723// Allocate memory for a new row with N_VARFLD var-len elements
5724// If out of memory, process is killed.
5725atf_amc::VarlenExtern& atf_amc::varlen_extern_Alloc(i32 n_varfld) {
5726 atf_amc::VarlenExtern* row = varlen_extern_AllocMaybe(n_varfld);
5727 if (UNLIKELY(row == NULL)) {
5728 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.FDb.varlen_extern comment:'Alloc failed'");
5729 }
5730 return *row;
5731}
5732
5733// --- atf_amc.FDb.varlen_extern.AllocExtra
5734atf_amc::VarlenExtern& atf_amc::varlen_extern_AllocExtra(void *extra, i32 nbyte_extra) {
5735 atf_amc::VarlenExtern *row = varlen_extern_AllocExtraMaybe(extra, nbyte_extra);
5736 if (UNLIKELY(row == NULL)) {
5737 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.FDb.varlen_extern comment:'Alloc failed'");
5738 }
5739 return *row;
5740}
5741
5742// --- atf_amc.FDb.varlen_extern.AllocExtraMaybe
5743// Allocate memory for new element. If out of memory, return NULL.
5744atf_amc::VarlenExtern* atf_amc::varlen_extern_AllocExtraMaybe(void *extra, i32 nbyte_extra) {
5745 atf_amc::VarlenExtern *row = (atf_amc::VarlenExtern*)varlen_extern_AllocMem(sizeof(atf_amc::VarlenExtern) + nbyte_extra);
5746 if (row) {
5747 new (row) atf_amc::VarlenExtern; // call constructor
5748 length_Set(*row, u32(sizeof(atf_amc::VarlenExtern) + nbyte_extra - 0));
5749 if (extra) {
5750 memcpy((u8*)row + sizeof(atf_amc::VarlenExtern), extra, nbyte_extra);
5751 }
5752 }
5753 return row;
5754}
5755
5756// --- atf_amc.FDb.varlen_extern.Delete
5757// Remove row from all global and cross indices, then deallocate row
5758void atf_amc::varlen_extern_Delete(atf_amc::VarlenExtern &row) {
5759 int length = i32(length_Get(row));
5760 row.~VarlenExtern();
5761 varlen_extern_FreeMem(&row, length);
5762}
5763
5764// --- atf_amc.FDb.varlen_extern.XrefMaybe
5765// Insert row into all appropriate indices. If error occurs, store error
5766// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
5767bool atf_amc::varlen_extern_XrefMaybe(atf_amc::VarlenExtern &row) {
5768 bool retval = true;
5769 (void)row;
5770 return retval;
5771}
5772
5773// --- atf_amc.FDb.amctest.Alloc
5774// Allocate memory for new default row.
5775// If out of memory, process is killed.
5776atf_amc::FAmctest& atf_amc::amctest_Alloc() {
5777 atf_amc::FAmctest* row = amctest_AllocMaybe();
5778 if (UNLIKELY(row == NULL)) {
5779 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.FDb.amctest comment:'Alloc failed'");
5780 }
5781 return *row;
5782}
5783
5784// --- atf_amc.FDb.amctest.AllocMaybe
5785// Allocate memory for new element. If out of memory, return NULL.
5786atf_amc::FAmctest* atf_amc::amctest_AllocMaybe() {
5787 atf_amc::FAmctest *row = (atf_amc::FAmctest*)amctest_AllocMem();
5788 if (row) {
5789 new (row) atf_amc::FAmctest; // call constructor
5790 }
5791 return row;
5792}
5793
5794// --- atf_amc.FDb.amctest.InsertMaybe
5795// Create new row from struct.
5796// Return pointer to new element, or NULL if insertion failed (due to out-of-memory, duplicate key, etc)
5797atf_amc::FAmctest* atf_amc::amctest_InsertMaybe(const atfdb::Amctest &value) {
5798 atf_amc::FAmctest *row = &amctest_Alloc(); // if out of memory, process dies. if input error, return NULL.
5799 amctest_CopyIn(*row,const_cast<atfdb::Amctest&>(value));
5800 bool ok = amctest_XrefMaybe(*row); // this may return false
5801 if (!ok) {
5802 amctest_RemoveLast(); // delete offending row, any existing xrefs are cleared
5803 row = NULL; // forget this ever happened
5804 }
5805 return row;
5806}
5807
5808// --- atf_amc.FDb.amctest.AllocMem
5809// Allocate space for one element. If no memory available, return NULL.
5810void* atf_amc::amctest_AllocMem() {
5811 u64 new_nelems = _db.amctest_n+1;
5812 // compute level and index on level
5813 u64 bsr = algo::u64_BitScanReverse(new_nelems);
5814 u64 base = u64(1)<<bsr;
5815 u64 index = new_nelems-base;
5816 void *ret = NULL;
5817 // if level doesn't exist yet, create it
5818 atf_amc::FAmctest* lev = NULL;
5819 if (bsr < 32) {
5820 lev = _db.amctest_lary[bsr];
5821 if (!lev) {
5822 lev=(atf_amc::FAmctest*)algo_lib::malloc_AllocMem(sizeof(atf_amc::FAmctest) * (u64(1)<<bsr));
5823 _db.amctest_lary[bsr] = lev;
5824 }
5825 }
5826 // allocate element from this level
5827 if (lev) {
5828 _db.amctest_n = i32(new_nelems);
5829 ret = lev + index;
5830 }
5831 return ret;
5832}
5833
5834// --- atf_amc.FDb.amctest.RemoveAll
5835// Remove all elements from Lary
5836void atf_amc::amctest_RemoveAll() {
5837 for (u64 n = _db.amctest_n; n>0; ) {
5838 n--;
5839 amctest_qFind(u64(n)).~FAmctest(); // destroy last element
5840 _db.amctest_n = i32(n);
5841 }
5842}
5843
5844// --- atf_amc.FDb.amctest.RemoveLast
5845// Delete last element of array. Do nothing if array is empty.
5846void atf_amc::amctest_RemoveLast() {
5847 u64 n = _db.amctest_n;
5848 if (n > 0) {
5849 n -= 1;
5850 amctest_qFind(u64(n)).~FAmctest();
5851 _db.amctest_n = i32(n);
5852 }
5853}
5854
5855// --- atf_amc.FDb.amctest.LoadStatic
5856static void atf_amc::amctest_LoadStatic() {
5857 static struct _t {
5858 const char *s;
5859 void (*step)();
5860 } data[] = {
5861 { "atfdb.amctest amctest:AmcSort comment:\"\"", atf_amc::amctest_AmcSort }
5862 ,{ "atfdb.amctest amctest:BhFirstChanged1 comment:\"\"", atf_amc::amctest_BhFirstChanged1 }
5863 ,{ "atfdb.amctest amctest:BhFirstChanged2 comment:\"Insert 100 items in ascending order -- check that trigger fires once\"", atf_amc::amctest_BhFirstChanged2 }
5864 ,{ "atfdb.amctest amctest:BhFirstChanged3 comment:\"Insert 100 items in descending order -- check that trigger fires for each\"", atf_amc::amctest_BhFirstChanged3 }
5865 ,{ "atfdb.amctest amctest:BheapCursor comment:\"Test bheap cursor, cascade deletion\"", atf_amc::amctest_BheapCursor }
5866 ,{ "atfdb.amctest amctest:BheapInsert100 comment:\"Ascending, descending, mixed\"", atf_amc::amctest_BheapInsert100 }
5867 ,{ "atfdb.amctest amctest:BigEndian comment:\"\"", atf_amc::amctest_BigEndian }
5868 ,{ "atfdb.amctest amctest:BigendFconst comment:\"\"", atf_amc::amctest_BigendFconst }
5869 ,{ "atfdb.amctest amctest:BitfldBitset comment:\"Test bitfield extraction/insertion when reading bitset field\"", atf_amc::amctest_BitfldBitset }
5870 ,{ "atfdb.amctest amctest:BitfldNet comment:\"Test bitfield extraction/insertion (big-endian storage)\"", atf_amc::amctest_BitfldNet }
5871 ,{ "atfdb.amctest amctest:BitfldTuple comment:\"Test bitfield extraction/insertion when reading tuple\"", atf_amc::amctest_BitfldTuple }
5872 ,{ "atfdb.amctest amctest:BitsetBitcurs comment:\"\"", atf_amc::amctest_BitsetBitcurs }
5873 ,{ "atfdb.amctest amctest:BitsetInlary16 comment:\"Bitset over Inlary u16\"", atf_amc::amctest_BitsetInlary16 }
5874 ,{ "atfdb.amctest amctest:BitsetTary64 comment:\"Bitset over Tary u64\"", atf_amc::amctest_BitsetTary64 }
5875 ,{ "atfdb.amctest amctest:BitsetVal128 comment:\"Bitset over single u128\"", atf_amc::amctest_BitsetVal128 }
5876 ,{ "atfdb.amctest amctest:BitsetVal64 comment:\"Bitset over single u64\"", atf_amc::amctest_BitsetVal64 }
5877 ,{ "atfdb.amctest amctest:BitsetVal8 comment:\"Bitset over single u8\"", atf_amc::amctest_BitsetVal8 }
5878 ,{ "atfdb.amctest amctest:CascdelAtree comment:\"Test for cascade deletion\"", atf_amc::amctest_CascdelAtree }
5879 ,{ "atfdb.amctest amctest:CascdelBheap comment:\"Test for cascade deletion\"", atf_amc::amctest_CascdelBheap }
5880 ,{ "atfdb.amctest amctest:CascdelBheapChain comment:\"Test for cascade deletion\"", atf_amc::amctest_CascdelBheapChain }
5881 ,{ "atfdb.amctest amctest:CascdelPtr comment:\"Test for cascade deletion\"", atf_amc::amctest_CascdelPtr }
5882 ,{ "atfdb.amctest amctest:CascdelPtrary comment:\"Test for cascade deletion\"", atf_amc::amctest_CascdelPtrary }
5883 ,{ "atfdb.amctest amctest:CascdelPtraryChain comment:\"Test for cascade deletion\"", atf_amc::amctest_CascdelPtraryChain }
5884 ,{ "atfdb.amctest amctest:CascdelThash comment:\"Test for cascade deletion\"", atf_amc::amctest_CascdelThash }
5885 ,{ "atfdb.amctest amctest:CascdelThashChain comment:\"Test for cascade deletion\"", atf_amc::amctest_CascdelThashChain }
5886 ,{ "atfdb.amctest amctest:CascdelZdlist comment:\"Test for cascade deletion\"", atf_amc::amctest_CascdelZdlist }
5887 ,{ "atfdb.amctest amctest:CascdelZdlistChain comment:\"Test for cascade deletion\"", atf_amc::amctest_CascdelZdlistChain }
5888 ,{ "atfdb.amctest amctest:CascdelZslist comment:\"Test for cascade deletion\"", atf_amc::amctest_CascdelZslist }
5889 ,{ "atfdb.amctest amctest:CascdelZslistChain comment:\"Test for cascade deletion\"", atf_amc::amctest_CascdelZslistChain }
5890 ,{ "atfdb.amctest amctest:CastDown comment:\"Cast from header to message\"", atf_amc::amctest_CastDown }
5891 ,{ "atfdb.amctest amctest:CastDownFail comment:\"Cast from header to unrelated message type\"", atf_amc::amctest_CastDownFail }
5892 ,{ "atfdb.amctest amctest:CastDownTooShort comment:\"Cast from header to message -- length too short\"", atf_amc::amctest_CastDownTooShort }
5893 ,{ "atfdb.amctest amctest:CastUp comment:\"Cast from message to its header\"", atf_amc::amctest_CastUp }
5894 ,{ "atfdb.amctest amctest:CdlistDfltCtor comment:\"\"", atf_amc::amctest_CdlistDfltCtor }
5895 ,{ "atfdb.amctest amctest:CdlistFlush100 comment:\"\"", atf_amc::amctest_CdlistFlush100 }
5896 ,{ "atfdb.amctest amctest:CdlistFlushEmpty comment:\"\"", atf_amc::amctest_CdlistFlushEmpty }
5897 ,{ "atfdb.amctest amctest:CdlistInsert1 comment:\"\"", atf_amc::amctest_CdlistInsert1 }
5898 ,{ "atfdb.amctest amctest:CdlistInsert2 comment:\"\"", atf_amc::amctest_CdlistInsert2 }
5899 ,{ "atfdb.amctest amctest:CdlistInsert3 comment:\"\"", atf_amc::amctest_CdlistInsert3 }
5900 ,{ "atfdb.amctest amctest:CdlistInsertHead1 comment:\"\"", atf_amc::amctest_CdlistInsertHead1 }
5901 ,{ "atfdb.amctest amctest:CdlistInsertHead2 comment:\"\"", atf_amc::amctest_CdlistInsertHead2 }
5902 ,{ "atfdb.amctest amctest:CdlistInsertHead3 comment:\"\"", atf_amc::amctest_CdlistInsertHead3 }
5903 ,{ "atfdb.amctest amctest:CdlistInsertMaybe comment:\"\"", atf_amc::amctest_CdlistInsertMaybe }
5904 ,{ "atfdb.amctest amctest:CdlistItemDfltCtor comment:\"\"", atf_amc::amctest_CdlistItemDfltCtor }
5905 ,{ "atfdb.amctest amctest:CdlistRemove comment:\"\"", atf_amc::amctest_CdlistRemove }
5906 ,{ "atfdb.amctest amctest:CdlistRemoveFirst comment:\"\"", atf_amc::amctest_CdlistRemoveFirst }
5907 ,{ "atfdb.amctest amctest:CdlistRotateFirst comment:\"\"", atf_amc::amctest_CdlistRotateFirst }
5908 ,{ "atfdb.amctest amctest:CleanupOrder comment:\"\"", atf_amc::amctest_CleanupOrder }
5909 ,{ "atfdb.amctest amctest:CopyOut1 comment:Pre-check", atf_amc::amctest_CopyOut1 }
5910 ,{ "atfdb.amctest amctest:CopyOut2 comment:\"Check that derived fields were copied to base\"", atf_amc::amctest_CopyOut2 }
5911 ,{ "atfdb.amctest amctest:CopyOut3 comment:\"Check that type/length fields were not copied to base\"", atf_amc::amctest_CopyOut3 }
5912 ,{ "atfdb.amctest amctest:CslistFirstChangedFlush comment:\"\"", atf_amc::amctest_CslistFirstChangedFlush }
5913 ,{ "atfdb.amctest amctest:CslistFirstChangedInsert comment:\"\"", atf_amc::amctest_CslistFirstChangedInsert }
5914 ,{ "atfdb.amctest amctest:CslistFirstChangedRemove comment:\"\"", atf_amc::amctest_CslistFirstChangedRemove }
5915 ,{ "atfdb.amctest amctest:CslistFirstChangedRemoveFirst comment:\"\"", atf_amc::amctest_CslistFirstChangedRemoveFirst }
5916 ,{ "atfdb.amctest amctest:CslistHeadFirstChangedInsert comment:\"\"", atf_amc::amctest_CslistHeadFirstChangedInsert }
5917 ,{ "atfdb.amctest amctest:CslistInsert1 comment:\"\"", atf_amc::amctest_CslistInsert1 }
5918 ,{ "atfdb.amctest amctest:CslistInsert2 comment:\"\"", atf_amc::amctest_CslistInsert2 }
5919 ,{ "atfdb.amctest amctest:CslistInsert3 comment:\"\"", atf_amc::amctest_CslistInsert3 }
5920 ,{ "atfdb.amctest amctest:CslistInsertHead1 comment:\"\"", atf_amc::amctest_CslistInsertHead1 }
5921 ,{ "atfdb.amctest amctest:CslistInsertHead2 comment:\"\"", atf_amc::amctest_CslistInsertHead2 }
5922 ,{ "atfdb.amctest amctest:CslistInsertHead3 comment:\"\"", atf_amc::amctest_CslistInsertHead3 }
5923 ,{ "atfdb.amctest amctest:CslistRemove comment:\"\"", atf_amc::amctest_CslistRemove }
5924 ,{ "atfdb.amctest amctest:CslistRemoveFirst comment:\"\"", atf_amc::amctest_CslistRemoveFirst }
5925 ,{ "atfdb.amctest amctest:CslistRotateFirst comment:\"\"", atf_amc::amctest_CslistRotateFirst }
5926 ,{ "atfdb.amctest amctest:Delptr comment:\"Test Delptr\"", atf_amc::amctest_Delptr }
5927 ,{ "atfdb.amctest amctest:DispRead1 comment:\"Read a message containing varlen char field\"", atf_amc::amctest_DispRead1 }
5928 ,{ "atfdb.amctest amctest:DispRead2 comment:\"Read a message containing several varlen fields\"", atf_amc::amctest_DispRead2 }
5929 ,{ "atfdb.amctest amctest:DispRead3 comment:\"Time reading\"", atf_amc::amctest_DispRead3 }
5930 ,{ "atfdb.amctest amctest:DispRead4 comment:\"Read Seqmsg with varlen payload\"", atf_amc::amctest_DispRead4 }
5931 ,{ "atfdb.amctest amctest:DispReadSsimfile comment:\"Use a Dispatch to read several tuples\"", atf_amc::amctest_DispReadSsimfile }
5932 ,{ "atfdb.amctest amctest:ExecSh comment:\"Execute subshell process\"", atf_amc::amctest_ExecSh }
5933 ,{ "atfdb.amctest amctest:ExecVerbose comment:\"Exec with verbose\"", atf_amc::amctest_ExecVerbose }
5934 ,{ "atfdb.amctest amctest:Exec_Status comment:\"Check return status of waitpid()\"", atf_amc::amctest_Exec_Status }
5935 ,{ "atfdb.amctest amctest:Fcmp comment:\"Test string comparison functions as generated with fcmp\"", atf_amc::amctest_Fcmp }
5936 ,{ "atfdb.amctest amctest:Fconst comment:\"Test for fconst\"", atf_amc::amctest_Fconst }
5937 ,{ "atfdb.amctest amctest:Gsymbol comment:\"Check gsymbol constants\"", atf_amc::amctest_Gsymbol }
5938 ,{ "atfdb.amctest amctest:Hook1 comment:\"Test Hook functions\"", atf_amc::amctest_Hook1 }
5939 ,{ "atfdb.amctest amctest:Hook2 comment:\"Test Hook functions\"", atf_amc::amctest_Hook2 }
5940 ,{ "atfdb.amctest amctest:ImdXref comment:\"\"", atf_amc::amctest_ImdXref }
5941 ,{ "atfdb.amctest amctest:Inlary_ReadPrint comment:\"Check Inlary read/print\"", atf_amc::amctest_Inlary_ReadPrint }
5942 ,{ "atfdb.amctest amctest:LaryFind comment:\"\"", atf_amc::amctest_LaryFind }
5943 ,{ "atfdb.amctest amctest:LineIter comment:\"Iterate over lines\"", atf_amc::amctest_LineIter }
5944 ,{ "atfdb.amctest amctest:Lpool comment:\"\"", atf_amc::amctest_Lpool }
5945 ,{ "atfdb.amctest amctest:LpoolLockMem comment:\"\"", atf_amc::amctest_LpoolLockMem }
5946 ,{ "atfdb.amctest amctest:Minmax comment:\"\"", atf_amc::amctest_Minmax }
5947 ,{ "atfdb.amctest amctest:MsgCurs comment:\"Check message cursor over memptr\"", atf_amc::amctest_MsgCurs }
5948 ,{ "atfdb.amctest amctest:MsgCurs2 comment:\"\"", atf_amc::amctest_MsgCurs2 }
5949 ,{ "atfdb.amctest amctest:MsgCurs3 comment:\"\"", atf_amc::amctest_MsgCurs3 }
5950 ,{ "atfdb.amctest amctest:MsgCurs4 comment:\"\"", atf_amc::amctest_MsgCurs4 }
5951 ,{ "atfdb.amctest amctest:MsgLength comment:\"Check GetMsgLength, GetMsgMemptr functions\"", atf_amc::amctest_MsgLength }
5952 ,{ "atfdb.amctest amctest:Numstr comment:\"\"", atf_amc::amctest_Numstr }
5953 ,{ "atfdb.amctest amctest:NumstrCorruption comment:\"Check that corruption doesn't occur during numstr formatting.\"", atf_amc::amctest_NumstrCorruption }
5954 ,{ "atfdb.amctest amctest:OptAlloc comment:\"\"", atf_amc::amctest_OptAlloc }
5955 ,{ "atfdb.amctest amctest:OptG comment:,", atf_amc::amctest_OptG }
5956 ,{ "atfdb.amctest amctest:OptG2 comment:\"Outer length too short\"", atf_amc::amctest_OptG2 }
5957 ,{ "atfdb.amctest amctest:OptG8 comment:\"Construct OptG in memptr\"", atf_amc::amctest_OptG8 }
5958 ,{ "atfdb.amctest amctest:OptG9 comment:\"Print struct with Opt member\"", atf_amc::amctest_OptG9 }
5959 ,{ "atfdb.amctest amctest:OptOptG10 comment:\"Read struct with Opt member\"", atf_amc::amctest_OptOptG10 }
5960 ,{ "atfdb.amctest amctest:OptOptG3 comment:\"Access valid opt varlen field successfully\"", atf_amc::amctest_OptOptG3 }
5961 ,{ "atfdb.amctest amctest:OptOptG4 comment:\"??\"", atf_amc::amctest_OptOptG4 }
5962 ,{ "atfdb.amctest amctest:OptOptG5 comment:\"Inner length too short\"", atf_amc::amctest_OptOptG5 }
5963 ,{ "atfdb.amctest amctest:OptOptG6 comment:\"Inner length extends past outer length\"", atf_amc::amctest_OptOptG6 }
5964 ,{ "atfdb.amctest amctest:OptOptG7 comment:\"Fetch two optional elements\"", atf_amc::amctest_OptOptG7 }
5965 ,{ "atfdb.amctest amctest:OptOptG8 comment:\"Construct OptOptG in memptr\"", atf_amc::amctest_OptOptG8 }
5966 ,{ "atfdb.amctest amctest:OptOptG9 comment:\"Print struct with Opt member\"", atf_amc::amctest_OptOptG9 }
5967 ,{ "atfdb.amctest amctest:PerfSortString comment:\"\"", atf_amc::amctest_PerfSortString }
5968 ,{ "atfdb.amctest amctest:PerfThashRemove comment:\"\"", atf_amc::amctest_PerfThashRemove }
5969 ,{ "atfdb.amctest amctest:PmaskMultiple comment:\"Check Pmask Multiple\"", atf_amc::amctest_PmaskMultiple }
5970 ,{ "atfdb.amctest amctest:PrintBase36 comment:\"\"", atf_amc::amctest_PrintBase36 }
5971 ,{ "atfdb.amctest amctest:PrintRawGconst comment:\"Check that gconst field within tuple is printed as raw\"", atf_amc::amctest_PrintRawGconst }
5972 ,{ "atfdb.amctest amctest:PtraryCursor comment:\"Test Ptrary cursor\"", atf_amc::amctest_PtraryCursor }
5973 ,{ "atfdb.amctest amctest:PtraryInsert comment:\"Insert/Remove invariants for Ptrary\"", atf_amc::amctest_PtraryInsert }
5974 ,{ "atfdb.amctest amctest:ReadProc comment:\"Read from subprocess\"", atf_amc::amctest_ReadProc }
5975 ,{ "atfdb.amctest amctest:ReadTuple1 comment:\"A single field is printed without field name\"", atf_amc::amctest_ReadTuple1 }
5976 ,{ "atfdb.amctest amctest:ReadTuple2 comment:\"Two fields are printed as name-value pairs.\"", atf_amc::amctest_ReadTuple2 }
5977 ,{ "atfdb.amctest amctest:ReadTuple2a comment:\"Two anon fields are printed as name-value pairs.\"", atf_amc::amctest_ReadTuple2a }
5978 ,{ "atfdb.amctest amctest:ReadTuple3 comment:Attr_curs", atf_amc::amctest_ReadTuple3 }
5979 ,{ "atfdb.amctest amctest:ReadTuple4 comment:\"Attr_curs -- empty string\"", atf_amc::amctest_ReadTuple4 }
5980 ,{ "atfdb.amctest amctest:ReadTuple5 comment:\"Attr_curs -- quoted strings\"", atf_amc::amctest_ReadTuple5 }
5981 ,{ "atfdb.amctest amctest:Scratch comment:\"Scratch area for new test development\"", atf_amc::amctest_Scratch }
5982 ,{ "atfdb.amctest amctest:SetGetnumBase10 comment:\"\"", atf_amc::amctest_SetGetnumBase10 }
5983 ,{ "atfdb.amctest amctest:SubstrDfltval comment:\"\"", atf_amc::amctest_SubstrDfltval }
5984 ,{ "atfdb.amctest amctest:TaryInit comment:\"u32: Add element to Tary, check that it's initialized\"", atf_amc::amctest_TaryInit }
5985 ,{ "atfdb.amctest amctest:TaryInit2 comment:\"u32: Add N elements to Tary, check that they're initialized\"", atf_amc::amctest_TaryInit2 }
5986 ,{ "atfdb.amctest amctest:TaryInit3 comment:\"u8: Add element to Tary, check that it's initialized\"", atf_amc::amctest_TaryInit3 }
5987 ,{ "atfdb.amctest amctest:TaryInit4 comment:\"u8: Add N elements to Tary, check that they're initialized\"", atf_amc::amctest_TaryInit4 }
5988 ,{ "atfdb.amctest amctest:TaryReserve comment:\"\"", atf_amc::amctest_TaryReserve }
5989 ,{ "atfdb.amctest amctest:TestBitfld comment:\"U16 bitfields: Set values, check that they were set\"", atf_amc::amctest_TestBitfld }
5990 ,{ "atfdb.amctest amctest:TestBitfld2 comment:\"U128 bitfields: Set values, check that they were set\"", atf_amc::amctest_TestBitfld2 }
5991 ,{ "atfdb.amctest amctest:TestCstring1 comment:\"Basic test\"", atf_amc::amctest_TestCstring1 }
5992 ,{ "atfdb.amctest amctest:TestCstring2 comment:\"Insert cstring.\"", atf_amc::amctest_TestCstring2 }
5993 ,{ "atfdb.amctest amctest:TestDispFilter comment:\"DispFilter Basic Match\"", atf_amc::amctest_TestDispFilter }
5994 ,{ "atfdb.amctest amctest:TestDispFilter2 comment:\"DispFilter Regx\"", atf_amc::amctest_TestDispFilter2 }
5995 ,{ "atfdb.amctest amctest:TestDispFilter3 comment:\"DispFilter Explicit int field\"", atf_amc::amctest_TestDispFilter3 }
5996 ,{ "atfdb.amctest amctest:TestDispFilter4 comment:\"DispFilter Date\"", atf_amc::amctest_TestDispFilter4 }
5997 ,{ "atfdb.amctest amctest:TestInsertX2 comment:\"Insert instance of TypeT, xrefing with type A\"", atf_amc::amctest_TestInsertX2 }
5998 ,{ "atfdb.amctest amctest:TestInsertX3 comment:\"Insert instance of TypeT, invalid xref with type A. Expect rollback\"", atf_amc::amctest_TestInsertX3 }
5999 ,{ "atfdb.amctest amctest:TestPmask1 comment:\"Default ctor, check that pmask field is !PresentQ\"", atf_amc::amctest_TestPmask1 }
6000 ,{ "atfdb.amctest amctest:TestPmask2 comment:\"Set field, check that field is PresentQ\"", atf_amc::amctest_TestPmask2 }
6001 ,{ "atfdb.amctest amctest:TestPmask3 comment:\"Read ctype from string that doesn't have pmask field. It must be !PresentQ\"", atf_amc::amctest_TestPmask3 }
6002 ,{ "atfdb.amctest amctest:TestPmask4 comment:\"Read ctype from string that has a pmask field. It must be PresentQ\"", atf_amc::amctest_TestPmask4 }
6003 ,{ "atfdb.amctest amctest:TestPmask5 comment:\"Check explicitly that pmask is being updated by Set\"", atf_amc::amctest_TestPmask5 }
6004 ,{ "atfdb.amctest amctest:TestPmask6 comment:\"Check that pmask isn't read from string\"", atf_amc::amctest_TestPmask6 }
6005 ,{ "atfdb.amctest amctest:TestPmask7 comment:\"Check that 128-bit pmask works.\"", atf_amc::amctest_TestPmask7 }
6006 ,{ "atfdb.amctest amctest:TestPmask8 comment:\"Check pmask-555.\"", atf_amc::amctest_TestPmask8 }
6007 ,{ "atfdb.amctest amctest:TestRegx1 comment:\"\"", atf_amc::amctest_TestRegx1 }
6008 ,{ "atfdb.amctest amctest:TestSep1 comment:\"Print Test\"", atf_amc::amctest_TestSep1 }
6009 ,{ "atfdb.amctest amctest:TestSep2 comment:\"Read Test\"", atf_amc::amctest_TestSep2 }
6010 ,{ "atfdb.amctest amctest:TestString comment:\"\"", atf_amc::amctest_TestString }
6011 ,{ "atfdb.amctest amctest:ThashEmpty comment:\"\"", atf_amc::amctest_ThashEmpty }
6012 ,{ "atfdb.amctest amctest:ThashFindRemove comment:\"\"", atf_amc::amctest_ThashFindRemove }
6013 ,{ "atfdb.amctest amctest:ThashGetOrCreate comment:\"\"", atf_amc::amctest_ThashGetOrCreate }
6014 ,{ "atfdb.amctest amctest:ThashInsertMaybe comment:\"\"", atf_amc::amctest_ThashInsertMaybe }
6015 ,{ "atfdb.amctest amctest:ThashRemove comment:\"\"", atf_amc::amctest_ThashRemove }
6016 ,{ "atfdb.amctest amctest:ThashXref comment:\"\"", atf_amc::amctest_ThashXref }
6017 ,{ "atfdb.amctest amctest:Typetag comment:\"\"", atf_amc::amctest_Typetag }
6018 ,{ "atfdb.amctest amctest:VarlenAlloc comment:\"\"", atf_amc::amctest_VarlenAlloc }
6019 ,{ "atfdb.amctest amctest:VarlenExternLength comment:\"\"", atf_amc::amctest_VarlenExternLength }
6020 ,{ "atfdb.amctest amctest:VarlenMsgs comment:\"Variable-length messages (Opt+Varlen)\"", atf_amc::amctest_VarlenMsgs }
6021 ,{ "atfdb.amctest amctest:VarlenMsgsPnew comment:\"Variable-length messages (Opt+Varlen) pnew\"", atf_amc::amctest_VarlenMsgsPnew }
6022 ,{ "atfdb.amctest amctest:ZdlistDelCurs comment:\"\"", atf_amc::amctest_ZdlistDelCurs }
6023 ,{ "atfdb.amctest amctest:ZdlistDfltCtor comment:\"\"", atf_amc::amctest_ZdlistDfltCtor }
6024 ,{ "atfdb.amctest amctest:ZdlistFlush100 comment:\"\"", atf_amc::amctest_ZdlistFlush100 }
6025 ,{ "atfdb.amctest amctest:ZdlistFlushEmpty comment:\"\"", atf_amc::amctest_ZdlistFlushEmpty }
6026 ,{ "atfdb.amctest amctest:ZdlistInsert1 comment:\"\"", atf_amc::amctest_ZdlistInsert1 }
6027 ,{ "atfdb.amctest amctest:ZdlistInsert2 comment:\"\"", atf_amc::amctest_ZdlistInsert2 }
6028 ,{ "atfdb.amctest amctest:ZdlistInsert3 comment:\"\"", atf_amc::amctest_ZdlistInsert3 }
6029 ,{ "atfdb.amctest amctest:ZdlistInsertHead1 comment:\"\"", atf_amc::amctest_ZdlistInsertHead1 }
6030 ,{ "atfdb.amctest amctest:ZdlistInsertHead2 comment:\"\"", atf_amc::amctest_ZdlistInsertHead2 }
6031 ,{ "atfdb.amctest amctest:ZdlistInsertHead3 comment:\"\"", atf_amc::amctest_ZdlistInsertHead3 }
6032 ,{ "atfdb.amctest amctest:ZdlistInsertHeadNoTail1 comment:\"\"", atf_amc::amctest_ZdlistInsertHeadNoTail1 }
6033 ,{ "atfdb.amctest amctest:ZdlistInsertHeadNoTail2 comment:\"\"", atf_amc::amctest_ZdlistInsertHeadNoTail2 }
6034 ,{ "atfdb.amctest amctest:ZdlistInsertHeadNoTail3 comment:\"\"", atf_amc::amctest_ZdlistInsertHeadNoTail3 }
6035 ,{ "atfdb.amctest amctest:ZdlistInsertMaybe comment:\"\"", atf_amc::amctest_ZdlistInsertMaybe }
6036 ,{ "atfdb.amctest amctest:ZdlistItemDfltCtor comment:\"\"", atf_amc::amctest_ZdlistItemDfltCtor }
6037 ,{ "atfdb.amctest amctest:ZdlistRemove comment:\"\"", atf_amc::amctest_ZdlistRemove }
6038 ,{ "atfdb.amctest amctest:ZdlistRemoveFirst comment:\"\"", atf_amc::amctest_ZdlistRemoveFirst }
6039 ,{ "atfdb.amctest amctest:ZslistFirstChangedFlush comment:\"\"", atf_amc::amctest_ZslistFirstChangedFlush }
6040 ,{ "atfdb.amctest amctest:ZslistFirstChangedInsert comment:\"\"", atf_amc::amctest_ZslistFirstChangedInsert }
6041 ,{ "atfdb.amctest amctest:ZslistFirstChangedRemove comment:\"\"", atf_amc::amctest_ZslistFirstChangedRemove }
6042 ,{ "atfdb.amctest amctest:ZslistFirstChangedRemoveFirst comment:\"\"", atf_amc::amctest_ZslistFirstChangedRemoveFirst }
6043 ,{ "atfdb.amctest amctest:ZslistHeadFirstChangedInsert comment:\"\"", atf_amc::amctest_ZslistHeadFirstChangedInsert }
6044 ,{ "atfdb.amctest amctest:ZslistInsert1 comment:\"\"", atf_amc::amctest_ZslistInsert1 }
6045 ,{ "atfdb.amctest amctest:ZslistInsert2 comment:\"\"", atf_amc::amctest_ZslistInsert2 }
6046 ,{ "atfdb.amctest amctest:ZslistInsert3 comment:\"\"", atf_amc::amctest_ZslistInsert3 }
6047 ,{ "atfdb.amctest amctest:ZslistInsertHead1 comment:\"\"", atf_amc::amctest_ZslistInsertHead1 }
6048 ,{ "atfdb.amctest amctest:ZslistInsertHead2 comment:\"\"", atf_amc::amctest_ZslistInsertHead2 }
6049 ,{ "atfdb.amctest amctest:ZslistInsertHead3 comment:\"\"", atf_amc::amctest_ZslistInsertHead3 }
6050 ,{ "atfdb.amctest amctest:ZslistRemove comment:\"\"", atf_amc::amctest_ZslistRemove }
6051 ,{ "atfdb.amctest amctest:ZslistRemoveFirst comment:\"\"", atf_amc::amctest_ZslistRemoveFirst }
6052 ,{ "atfdb.amctest amctest:Zslistmt1 comment:\"\"", atf_amc::amctest_Zslistmt1 }
6053 ,{ "atfdb.amctest amctest:Zslistmt2 comment:\"\"", atf_amc::amctest_Zslistmt2 }
6054 ,{ "atfdb.amctest amctest:Zslistmt3 comment:\"\"", atf_amc::amctest_Zslistmt3 }
6055 ,{ "atfdb.amctest amctest:ZslistmtDfltCtor comment:\"\"", atf_amc::amctest_ZslistmtDfltCtor }
6056 ,{ "atfdb.amctest amctest:ZslistmtItemDfltCtor comment:\"\"", atf_amc::amctest_ZslistmtItemDfltCtor }
6057 ,{ "atfdb.amctest amctest:atree_RangeSearch comment:\"Range searching on atree\"", atf_amc::amctest_atree_RangeSearch }
6058 ,{ "atfdb.amctest amctest:atree_test1 comment:\"Play with the tree, constantly verify invariants\"", atf_amc::amctest_atree_test1 }
6059 ,{ "atfdb.amctest amctest:atree_test2 comment:\"Test FirstGe and LastLt\"", atf_amc::amctest_atree_test2 }
6060 ,{ "atfdb.amctest amctest:bytebuf_dyn_test1 comment:\"Check buffer sizes\"", atf_amc::amctest_bytebuf_dyn_test1 }
6061 ,{ "atfdb.amctest amctest:bytebuf_test1 comment:\"Initial state -- no data\"", atf_amc::amctest_bytebuf_test1 }
6062 ,{ "atfdb.amctest amctest:bytebuf_test2 comment:\"Write some bytes, read back\"", atf_amc::amctest_bytebuf_test2 }
6063 ,{ "atfdb.amctest amctest:fstep_Inline comment:\"Check step type\"", atf_amc::amctest_fstep_Inline }
6064 ,{ "atfdb.amctest amctest:fstep_InlineOnce comment:\"Check step type\"", atf_amc::amctest_fstep_InlineOnce }
6065 ,{ "atfdb.amctest amctest:fstep_InlineRecur comment:\"Check step type\"", atf_amc::amctest_fstep_InlineRecur }
6066 ,{ "atfdb.amctest amctest:fstep_TimeHookRecur comment:\"Check step type\"", atf_amc::amctest_fstep_TimeHookRecur }
6067 ,{ "atfdb.amctest amctest:linebuf_test1 comment:\"Initial state -- no line\"", atf_amc::amctest_linebuf_test1 }
6068 ,{ "atfdb.amctest amctest:linebuf_test2 comment:\"write a line, read line back\"", atf_amc::amctest_linebuf_test2 }
6069 ,{ "atfdb.amctest amctest:linebuf_test3 comment:\"write a line in two phases, no message in between\"", atf_amc::amctest_linebuf_test3 }
6070 ,{ "atfdb.amctest amctest:linebuf_test4 comment:\"Write an empty line, read line back\"", atf_amc::amctest_linebuf_test4 }
6071 ,{ "atfdb.amctest amctest:linebuf_test5 comment:\"Line too large -- will never fit. Set EOF\"", atf_amc::amctest_linebuf_test5 }
6072 ,{ "atfdb.amctest amctest:msgbuf_extra_test comment:\"Write messages with extra len to temp buffer and read them\"", atf_amc::amctest_msgbuf_extra_test }
6073 ,{ "atfdb.amctest amctest:msgbuf_test0 comment:\"initial state - no message\"", atf_amc::amctest_msgbuf_test0 }
6074 ,{ "atfdb.amctest amctest:msgbuf_test1 comment:\"write message, read message back\"", atf_amc::amctest_msgbuf_test1 }
6075 ,{ "atfdb.amctest amctest:msgbuf_test10 comment:\"Force 10,000 messages of various sizes through a pipe\"", atf_amc::amctest_msgbuf_test10 }
6076 ,{ "atfdb.amctest amctest:msgbuf_test1_1 comment:\"write partial message, read should fail\"", atf_amc::amctest_msgbuf_test1_1 }
6077 ,{ "atfdb.amctest amctest:msgbuf_test1_2 comment:\"write message, call RemoveAll, read should fail\"", atf_amc::amctest_msgbuf_test1_2 }
6078 ,{ "atfdb.amctest amctest:msgbuf_test2 comment:\"good message, then not enough data.\"", atf_amc::amctest_msgbuf_test2 }
6079 ,{ "atfdb.amctest amctest:msgbuf_test3 comment:\"good message, then not enough data\"", atf_amc::amctest_msgbuf_test3 }
6080 ,{ "atfdb.amctest amctest:msgbuf_test4 comment:\"message, read partial message, supply new data, read message\"", atf_amc::amctest_msgbuf_test4 }
6081 ,{ "atfdb.amctest amctest:msgbuf_test5 comment:\"If GetMsg returns NULL, buffer is removed from read list\"", atf_amc::amctest_msgbuf_test5 }
6082 ,{ "atfdb.amctest amctest:msgbuf_test6 comment:\"Write runt message to buffer, check that eof and error flags are set\"", atf_amc::amctest_msgbuf_test6 }
6083 ,{ "atfdb.amctest amctest:msgbuf_test7 comment:\"Write HUGE message to buffer, check that error flag is set\"", atf_amc::amctest_msgbuf_test7 }
6084 ,{ "atfdb.amctest amctest:msgbuf_test8 comment:\"Write message to pipe, read it\"", atf_amc::amctest_msgbuf_test8 }
6085 ,{ "atfdb.amctest amctest:msgbuf_test9 comment:\"Write 2 messages to temp buffer. Feed them 1 by one through buffer\"", atf_amc::amctest_msgbuf_test9 }
6086 ,{NULL, NULL}
6087 };
6088 (void)data;
6089 atfdb::Amctest amctest;
6090 for (int i=0; data[i].s; i++) {
6091 (void)atfdb::Amctest_ReadStrptrMaybe(amctest, algo::strptr(data[i].s));
6092 atf_amc::FAmctest *elem = amctest_InsertMaybe(amctest);
6093 vrfy(elem, tempstr("atf_amc.static_insert_fatal_error")
6094 << Keyval("tuple",algo::strptr(data[i].s))
6095 << Keyval("comment",algo_lib::DetachBadTags()));
6096 elem->step = data[i].step;
6097 }
6098}
6099
6100// --- atf_amc.FDb.amctest.XrefMaybe
6101// Insert row into all appropriate indices. If error occurs, store error
6102// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
6103bool atf_amc::amctest_XrefMaybe(atf_amc::FAmctest &row) {
6104 bool retval = true;
6105 (void)row;
6106 return retval;
6107}
6108
6109// --- atf_amc.FDb.cascdel.Alloc
6110// Allocate memory for new default row.
6111// If out of memory, process is killed.
6112atf_amc::FCascdel& atf_amc::cascdel_Alloc() {
6113 atf_amc::FCascdel* row = cascdel_AllocMaybe();
6114 if (UNLIKELY(row == NULL)) {
6115 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.FDb.cascdel comment:'Alloc failed'");
6116 }
6117 return *row;
6118}
6119
6120// --- atf_amc.FDb.cascdel.AllocMaybe
6121// Allocate memory for new element. If out of memory, return NULL.
6122atf_amc::FCascdel* atf_amc::cascdel_AllocMaybe() {
6123 atf_amc::FCascdel *row = (atf_amc::FCascdel*)cascdel_AllocMem();
6124 if (row) {
6125 new (row) atf_amc::FCascdel; // call constructor
6126 }
6127 return row;
6128}
6129
6130// --- atf_amc.FDb.cascdel.Delete
6131// Remove row from all global and cross indices, then deallocate row
6132void atf_amc::cascdel_Delete(atf_amc::FCascdel &row) {
6133 row.~FCascdel();
6134 cascdel_FreeMem(row);
6135}
6136
6137// --- atf_amc.FDb.cascdel.AllocMem
6138// Allocate space for one element
6139// If no memory available, return NULL.
6140void* atf_amc::cascdel_AllocMem() {
6141 atf_amc::FCascdel *row = _db.cascdel_free;
6142 if (UNLIKELY(!row)) {
6143 cascdel_Reserve(1);
6144 row = _db.cascdel_free;
6145 }
6146 if (row) {
6147 _db.cascdel_free = row->cascdel_next;
6148 }
6149 return row;
6150}
6151
6152// --- atf_amc.FDb.cascdel.FreeMem
6153// Remove mem from all global and cross indices, then deallocate mem
6154void atf_amc::cascdel_FreeMem(atf_amc::FCascdel &row) {
6155 if (UNLIKELY(row.cascdel_next != (atf_amc::FCascdel*)-1)) {
6156 FatalErrorExit("atf_amc.tpool_double_delete pool:atf_amc.FDb.cascdel comment:'double deletion caught'");
6157 }
6158 row.cascdel_next = _db.cascdel_free; // insert into free list
6159 _db.cascdel_free = &row;
6160}
6161
6162// --- atf_amc.FDb.cascdel.Reserve
6163// Preallocate memory for N more elements
6164// Return number of elements actually reserved.
6165u64 atf_amc::cascdel_Reserve(u64 n_elems) {
6166 u64 ret = 0;
6167 while (ret < n_elems) {
6168 u64 size = _db.cascdel_blocksize; // underlying allocator is probably Lpool
6169 u64 reserved = cascdel_ReserveMem(size);
6170 ret += reserved;
6171 if (reserved == 0) {
6172 break;
6173 }
6174 }
6175 return ret;
6176}
6177
6178// --- atf_amc.FDb.cascdel.ReserveMem
6179// Allocate block of given size, break up into small elements and append to free list.
6180// Return number of elements reserved.
6181u64 atf_amc::cascdel_ReserveMem(u64 size) {
6182 u64 ret = 0;
6183 if (size >= sizeof(atf_amc::FCascdel)) {
6184 atf_amc::FCascdel *mem = (atf_amc::FCascdel*)algo_lib::malloc_AllocMem(size);
6185 ret = mem ? size / sizeof(atf_amc::FCascdel) : 0;
6186 // add newly allocated elements to the free list;
6187 for (u64 i=0; i < ret; i++) {
6188 mem[i].cascdel_next = _db.cascdel_free;
6189 _db.cascdel_free = mem+i;
6190 }
6191 }
6192 return ret;
6193}
6194
6195// --- atf_amc.FDb.cascdel.XrefMaybe
6196// Insert row into all appropriate indices. If error occurs, store error
6197// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
6198bool atf_amc::cascdel_XrefMaybe(atf_amc::FCascdel &row) {
6199 bool retval = true;
6200 (void)row;
6201 atf_amc::FCascdel* p_p_parent = row.p_parent;
6202 if (UNLIKELY(!p_p_parent)) {
6203 algo_lib::ResetErrtext() << "atf_amc.null_ref xref:atf_amc.FCascdel.child_ptr";
6204 return false;
6205 }
6206 // insert cascdel into index child_ptr
6207 if (row.p_parent != &row && row.type==atf_amc_FCascdel_type_ptr) { // user-defined insert condition
6208 bool success = child_ptr_InsertMaybe(*p_p_parent, row);
6209 if (UNLIKELY(!success)) {
6210 ch_RemoveAll(algo_lib::_db.errtext);
6211 algo_lib::_db.errtext << "atf_amc.duplicate_key xref:atf_amc.FCascdel.child_ptr"; // check for duplicate key
6212 return false;
6213 }
6214 }
6215 // insert cascdel into index c_child_ptrary
6216 if (row.p_parent != &row && row.type==atf_amc_FCascdel_type_ptrary) { // user-defined insert condition
6217 c_child_ptrary_Insert(*p_p_parent, row);
6218 }
6219 // insert cascdel into index ind_child_thash
6220 if (row.p_parent != &row && row.type==atf_amc_FCascdel_type_thash) { // user-defined insert condition
6221 bool success = ind_child_thash_InsertMaybe(*p_p_parent, row);
6222 if (UNLIKELY(!success)) {
6223 ch_RemoveAll(algo_lib::_db.errtext);
6224 algo_lib::_db.errtext << "atf_amc.duplicate_key xref:atf_amc.FCascdel.ind_child_thash"; // check for duplicate key
6225 return false;
6226 }
6227 }
6228 // insert cascdel into index bh_child_bheap
6229 if (row.p_parent != &row && row.type==atf_amc_FCascdel_type_bheap) { // user-defined insert condition
6230 bh_child_bheap_Insert(*p_p_parent, row);
6231 }
6232 // insert cascdel into index zd_childlist
6233 if (row.p_parent != &row && row.type==atf_amc_FCascdel_type_zdlist) { // user-defined insert condition
6234 zd_childlist_Insert(*p_p_parent, row);
6235 }
6236 // insert cascdel into index tr_child_atree
6237 if (row.p_parent != &row && row.type==atf_amc_FCascdel_type_atree) { // user-defined insert condition
6238 tr_child_atree_Insert(*p_p_parent, row);
6239 }
6240 return retval;
6241}
6242
6243// --- atf_amc.FDb.optalloc.FreeMem
6244// Free block of memory previously returned by Lpool.
6245void atf_amc::optalloc_FreeMem(void* mem, u64 size) {
6246 size = u64_Max(size,1ULL<<4);
6247 u64 cell = algo::u64_BitScanReverse(size-1) + 1 - 4;
6248 if (mem && cell < 36) {
6249 optalloc_Lpblock *temp = (optalloc_Lpblock*)mem; // push singly linked list
6250 temp->next = _db.optalloc_free[cell];
6251 _db.optalloc_free[cell] = temp;
6252 _db.optalloc_n--;
6253 }
6254}
6255
6256// --- atf_amc.FDb.optalloc.AllocMem
6257// Allocate new piece of memory at least SIZE bytes long.
6258// If not successful, return NULL
6259// The allocated block is at least 1<<4
6260// The maximum allocation size is at most 1<<(36+4)
6261void* atf_amc::optalloc_AllocMem(u64 size) {
6262 void *retval = NULL;
6263 size = u64_Max(size,1<<4); // enforce alignment
6264 u64 cell = algo::u64_BitScanReverse(size-1) + 1 - 4;
6265 if (cell < 36) {
6266 u64 i = cell;
6267 // try to find a block that's at least as large as required.
6268 // if found, remove from free list
6269 for (; i < 36; i++) {
6270 optalloc_Lpblock *blk = _db.optalloc_free[i];
6271 if (blk) {
6272 _db.optalloc_free[i] = blk->next;
6273 retval = blk;
6274 break;
6275 }
6276 }
6277 // if suitable size block is not found, create a new one
6278 // by requesting a block from the base allocator.
6279 if (UNLIKELY(!retval)) {
6280 i = u64_Max(cell, 21-4); // 2MB min -- allow huge page to be used
6281 retval = algo_lib::malloc_AllocMem(1ULL<<(i+4));
6282 }
6283 if (LIKELY(retval)) {
6284 // if block is more than 2x as large as needed, return the upper half to the free
6285 // list (repeatedly). meanwhile, retval doesn't change.
6286 while (i > cell) {
6287 i--;
6288 int half = 1ULL<<(i+4);
6289 optalloc_Lpblock *blk = (optalloc_Lpblock*)((u8*)retval + half);
6290 blk->next = _db.optalloc_free[i];
6291 _db.optalloc_free[i] = blk;
6292 }
6293 }
6294 _db.optalloc_n += retval != NULL;
6295 }
6296 return retval;
6297}
6298
6299// --- atf_amc.FDb.optalloc.ReserveBuffers
6300// Add N buffers of some size to the free store
6301// Reserve NBUF buffers of size BUFSIZE from the base pool (algo_lib::malloc)
6302bool atf_amc::optalloc_ReserveBuffers(u64 nbuf, u64 bufsize) {
6303 bool retval = true;
6304 bufsize = u64_Max(bufsize, 1<<4);
6305 u64 cell = algo::u64_BitScanReverse(bufsize-1) + 1 - 4;
6306 if (cell < 36) {
6307 for (u64 i = 0; i < nbuf; i++) {
6308 u64 size = 1ULL<<(cell+4);
6309 optalloc_Lpblock *temp = (optalloc_Lpblock*)algo_lib::malloc_AllocMem(size);
6310 if (temp == NULL) {
6311 retval = false;
6312 break;// why continue?
6313 } else {
6314 temp->next = _db.optalloc_free[cell];
6315 _db.optalloc_free[cell] = temp;
6316 }
6317 }
6318 }
6319 return retval;
6320}
6321
6322// --- atf_amc.FDb.optalloc.ReallocMem
6323// Allocate new block, copy old to new, delete old.
6324// If the new size is same as old size, do nothing.
6325// In all other cases, new memory is allocated (i.e. size reduction is not a no-op)
6326// If no memory, return NULL; old memory remains untouched
6327void* atf_amc::optalloc_ReallocMem(void* oldmem, u64 old_size, u64 new_size) {
6328 void *ret = oldmem;
6329 if (new_size != old_size) {
6330 ret = optalloc_AllocMem(new_size);
6331 if (ret && oldmem) {
6332 memcpy(ret,oldmem,u64_Min(new_size,old_size));
6333 optalloc_FreeMem(oldmem, old_size);
6334 }
6335 }
6336 return ret;
6337}
6338
6339// --- atf_amc.FDb.optalloc.AllocExtra
6340atf_amc::OptAlloc& atf_amc::optalloc_AllocExtra(void *extra, i32 nbyte_extra) {
6341 atf_amc::OptAlloc *row = optalloc_AllocExtraMaybe(extra, nbyte_extra);
6342 if (UNLIKELY(row == NULL)) {
6343 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.FDb.optalloc comment:'Alloc failed'");
6344 }
6345 return *row;
6346}
6347
6348// --- atf_amc.FDb.optalloc.AllocExtraMaybe
6349// Allocate memory for new element. If out of memory, return NULL.
6350atf_amc::OptAlloc* atf_amc::optalloc_AllocExtraMaybe(void *extra, i32 nbyte_extra) {
6351 atf_amc::OptAlloc *row = (atf_amc::OptAlloc*)optalloc_AllocMem(sizeof(atf_amc::OptAlloc) + nbyte_extra);
6352 if (row) {
6353 new (row) atf_amc::OptAlloc; // call constructor
6354 row->length = u32(sizeof(atf_amc::OptAlloc) + nbyte_extra - 0);
6355 if (extra) {
6356 memcpy((u8*)row + sizeof(atf_amc::OptAlloc), extra, nbyte_extra);
6357 }
6358 }
6359 return row;
6360}
6361
6362// --- atf_amc.FDb.optalloc.Delete
6363// Remove row from all global and cross indices, then deallocate row
6364void atf_amc::optalloc_Delete(atf_amc::OptAlloc &row) {
6365 int length = i32(row.length);
6366 row.~OptAlloc();
6367 optalloc_FreeMem(&row, length);
6368}
6369
6370// --- atf_amc.FDb.optalloc.XrefMaybe
6371// Insert row into all appropriate indices. If error occurs, store error
6372// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
6373bool atf_amc::optalloc_XrefMaybe(atf_amc::OptAlloc &row) {
6374 bool retval = true;
6375 (void)row;
6376 return retval;
6377}
6378
6379// --- atf_amc.FDb.varlenalloc.FreeMem
6380// Free block of memory previously returned by Lpool.
6381void atf_amc::varlenalloc_FreeMem(void* mem, u64 size) {
6382 size = u64_Max(size,1ULL<<4);
6383 u64 cell = algo::u64_BitScanReverse(size-1) + 1 - 4;
6384 if (mem && cell < 36) {
6385 varlenalloc_Lpblock *temp = (varlenalloc_Lpblock*)mem; // push singly linked list
6386 temp->next = _db.varlenalloc_free[cell];
6387 _db.varlenalloc_free[cell] = temp;
6388 _db.varlenalloc_n--;
6389 }
6390}
6391
6392// --- atf_amc.FDb.varlenalloc.AllocMem
6393// Allocate new piece of memory at least SIZE bytes long.
6394// If not successful, return NULL
6395// The allocated block is at least 1<<4
6396// The maximum allocation size is at most 1<<(36+4)
6397void* atf_amc::varlenalloc_AllocMem(u64 size) {
6398 void *retval = NULL;
6399 size = u64_Max(size,1<<4); // enforce alignment
6400 u64 cell = algo::u64_BitScanReverse(size-1) + 1 - 4;
6401 if (cell < 36) {
6402 u64 i = cell;
6403 // try to find a block that's at least as large as required.
6404 // if found, remove from free list
6405 for (; i < 36; i++) {
6406 varlenalloc_Lpblock *blk = _db.varlenalloc_free[i];
6407 if (blk) {
6408 _db.varlenalloc_free[i] = blk->next;
6409 retval = blk;
6410 break;
6411 }
6412 }
6413 // if suitable size block is not found, create a new one
6414 // by requesting a block from the base allocator.
6415 if (UNLIKELY(!retval)) {
6416 i = u64_Max(cell, 21-4); // 2MB min -- allow huge page to be used
6417 retval = algo_lib::malloc_AllocMem(1ULL<<(i+4));
6418 }
6419 if (LIKELY(retval)) {
6420 // if block is more than 2x as large as needed, return the upper half to the free
6421 // list (repeatedly). meanwhile, retval doesn't change.
6422 while (i > cell) {
6423 i--;
6424 int half = 1ULL<<(i+4);
6425 varlenalloc_Lpblock *blk = (varlenalloc_Lpblock*)((u8*)retval + half);
6426 blk->next = _db.varlenalloc_free[i];
6427 _db.varlenalloc_free[i] = blk;
6428 }
6429 }
6430 _db.varlenalloc_n += retval != NULL;
6431 }
6432 return retval;
6433}
6434
6435// --- atf_amc.FDb.varlenalloc.ReserveBuffers
6436// Add N buffers of some size to the free store
6437// Reserve NBUF buffers of size BUFSIZE from the base pool (algo_lib::malloc)
6438bool atf_amc::varlenalloc_ReserveBuffers(u64 nbuf, u64 bufsize) {
6439 bool retval = true;
6440 bufsize = u64_Max(bufsize, 1<<4);
6441 u64 cell = algo::u64_BitScanReverse(bufsize-1) + 1 - 4;
6442 if (cell < 36) {
6443 for (u64 i = 0; i < nbuf; i++) {
6444 u64 size = 1ULL<<(cell+4);
6445 varlenalloc_Lpblock *temp = (varlenalloc_Lpblock*)algo_lib::malloc_AllocMem(size);
6446 if (temp == NULL) {
6447 retval = false;
6448 break;// why continue?
6449 } else {
6450 temp->next = _db.varlenalloc_free[cell];
6451 _db.varlenalloc_free[cell] = temp;
6452 }
6453 }
6454 }
6455 return retval;
6456}
6457
6458// --- atf_amc.FDb.varlenalloc.ReallocMem
6459// Allocate new block, copy old to new, delete old.
6460// If the new size is same as old size, do nothing.
6461// In all other cases, new memory is allocated (i.e. size reduction is not a no-op)
6462// If no memory, return NULL; old memory remains untouched
6463void* atf_amc::varlenalloc_ReallocMem(void* oldmem, u64 old_size, u64 new_size) {
6464 void *ret = oldmem;
6465 if (new_size != old_size) {
6466 ret = varlenalloc_AllocMem(new_size);
6467 if (ret && oldmem) {
6468 memcpy(ret,oldmem,u64_Min(new_size,old_size));
6469 varlenalloc_FreeMem(oldmem, old_size);
6470 }
6471 }
6472 return ret;
6473}
6474
6475// --- atf_amc.FDb.varlenalloc.Alloc
6476// Allocate memory for a new row with N_VARFLD var-len elements
6477// If out of memory, process is killed.
6478atf_amc::VarlenAlloc& atf_amc::varlenalloc_Alloc(i32 n_varfld) {
6479 atf_amc::VarlenAlloc* row = varlenalloc_AllocMaybe(n_varfld);
6480 if (UNLIKELY(row == NULL)) {
6481 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.FDb.varlenalloc comment:'Alloc failed'");
6482 }
6483 return *row;
6484}
6485
6486// --- atf_amc.FDb.varlenalloc.AllocExtra
6487atf_amc::VarlenAlloc& atf_amc::varlenalloc_AllocExtra(void *extra, i32 nbyte_extra) {
6488 atf_amc::VarlenAlloc *row = varlenalloc_AllocExtraMaybe(extra, nbyte_extra);
6489 if (UNLIKELY(row == NULL)) {
6490 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.FDb.varlenalloc comment:'Alloc failed'");
6491 }
6492 return *row;
6493}
6494
6495// --- atf_amc.FDb.varlenalloc.AllocExtraMaybe
6496// Allocate memory for new element. If out of memory, return NULL.
6497atf_amc::VarlenAlloc* atf_amc::varlenalloc_AllocExtraMaybe(void *extra, i32 nbyte_extra) {
6498 atf_amc::VarlenAlloc *row = (atf_amc::VarlenAlloc*)varlenalloc_AllocMem(sizeof(atf_amc::VarlenAlloc) + nbyte_extra);
6499 if (row) {
6500 new (row) atf_amc::VarlenAlloc; // call constructor
6501 row->length = u32(sizeof(atf_amc::VarlenAlloc) + nbyte_extra - 0);
6502 if (extra) {
6503 memcpy((u8*)row + sizeof(atf_amc::VarlenAlloc), extra, nbyte_extra);
6504 }
6505 }
6506 return row;
6507}
6508
6509// --- atf_amc.FDb.varlenalloc.Delete
6510// Remove row from all global and cross indices, then deallocate row
6511void atf_amc::varlenalloc_Delete(atf_amc::VarlenAlloc &row) {
6512 int length = i32(row.length);
6513 row.~VarlenAlloc();
6514 varlenalloc_FreeMem(&row, length);
6515}
6516
6517// --- atf_amc.FDb.varlenalloc.XrefMaybe
6518// Insert row into all appropriate indices. If error occurs, store error
6519// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
6520bool atf_amc::varlenalloc_XrefMaybe(atf_amc::VarlenAlloc &row) {
6521 bool retval = true;
6522 (void)row;
6523 return retval;
6524}
6525
6526// --- atf_amc.FDb.optg.FreeMem
6527// Free block of memory previously returned by Lpool.
6528void atf_amc::optg_FreeMem(void* mem, u64 size) {
6529 size = u64_Max(size,1ULL<<4);
6530 u64 cell = algo::u64_BitScanReverse(size-1) + 1 - 4;
6531 if (mem && cell < 36) {
6532 optg_Lpblock *temp = (optg_Lpblock*)mem; // push singly linked list
6533 temp->next = _db.optg_free[cell];
6534 _db.optg_free[cell] = temp;
6535 _db.optg_n--;
6536 }
6537}
6538
6539// --- atf_amc.FDb.optg.AllocMem
6540// Allocate new piece of memory at least SIZE bytes long.
6541// If not successful, return NULL
6542// The allocated block is at least 1<<4
6543// The maximum allocation size is at most 1<<(36+4)
6544void* atf_amc::optg_AllocMem(u64 size) {
6545 void *retval = NULL;
6546 size = u64_Max(size,1<<4); // enforce alignment
6547 u64 cell = algo::u64_BitScanReverse(size-1) + 1 - 4;
6548 if (cell < 36) {
6549 u64 i = cell;
6550 // try to find a block that's at least as large as required.
6551 // if found, remove from free list
6552 for (; i < 36; i++) {
6553 optg_Lpblock *blk = _db.optg_free[i];
6554 if (blk) {
6555 _db.optg_free[i] = blk->next;
6556 retval = blk;
6557 break;
6558 }
6559 }
6560 // if suitable size block is not found, create a new one
6561 // by requesting a block from the base allocator.
6562 if (UNLIKELY(!retval)) {
6563 i = u64_Max(cell, 21-4); // 2MB min -- allow huge page to be used
6564 retval = algo_lib::malloc_AllocMem(1ULL<<(i+4));
6565 }
6566 if (LIKELY(retval)) {
6567 // if block is more than 2x as large as needed, return the upper half to the free
6568 // list (repeatedly). meanwhile, retval doesn't change.
6569 while (i > cell) {
6570 i--;
6571 int half = 1ULL<<(i+4);
6572 optg_Lpblock *blk = (optg_Lpblock*)((u8*)retval + half);
6573 blk->next = _db.optg_free[i];
6574 _db.optg_free[i] = blk;
6575 }
6576 }
6577 _db.optg_n += retval != NULL;
6578 }
6579 return retval;
6580}
6581
6582// --- atf_amc.FDb.optg.ReserveBuffers
6583// Add N buffers of some size to the free store
6584// Reserve NBUF buffers of size BUFSIZE from the base pool (algo_lib::malloc)
6585bool atf_amc::optg_ReserveBuffers(u64 nbuf, u64 bufsize) {
6586 bool retval = true;
6587 bufsize = u64_Max(bufsize, 1<<4);
6588 u64 cell = algo::u64_BitScanReverse(bufsize-1) + 1 - 4;
6589 if (cell < 36) {
6590 for (u64 i = 0; i < nbuf; i++) {
6591 u64 size = 1ULL<<(cell+4);
6592 optg_Lpblock *temp = (optg_Lpblock*)algo_lib::malloc_AllocMem(size);
6593 if (temp == NULL) {
6594 retval = false;
6595 break;// why continue?
6596 } else {
6597 temp->next = _db.optg_free[cell];
6598 _db.optg_free[cell] = temp;
6599 }
6600 }
6601 }
6602 return retval;
6603}
6604
6605// --- atf_amc.FDb.optg.ReallocMem
6606// Allocate new block, copy old to new, delete old.
6607// If the new size is same as old size, do nothing.
6608// In all other cases, new memory is allocated (i.e. size reduction is not a no-op)
6609// If no memory, return NULL; old memory remains untouched
6610void* atf_amc::optg_ReallocMem(void* oldmem, u64 old_size, u64 new_size) {
6611 void *ret = oldmem;
6612 if (new_size != old_size) {
6613 ret = optg_AllocMem(new_size);
6614 if (ret && oldmem) {
6615 memcpy(ret,oldmem,u64_Min(new_size,old_size));
6616 optg_FreeMem(oldmem, old_size);
6617 }
6618 }
6619 return ret;
6620}
6621
6622// --- atf_amc.FDb.optg.AllocExtra
6623atf_amc::FOptG& atf_amc::optg_AllocExtra(void *extra, i32 nbyte_extra) {
6624 atf_amc::FOptG *row = optg_AllocExtraMaybe(extra, nbyte_extra);
6625 if (UNLIKELY(row == NULL)) {
6626 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.FDb.optg comment:'Alloc failed'");
6627 }
6628 return *row;
6629}
6630
6631// --- atf_amc.FDb.optg.AllocExtraMaybe
6632// Allocate memory for new element. If out of memory, return NULL.
6633atf_amc::FOptG* atf_amc::optg_AllocExtraMaybe(void *extra, i32 nbyte_extra) {
6634 atf_amc::FOptG *row = (atf_amc::FOptG*)optg_AllocMem(sizeof(atf_amc::FOptG) + nbyte_extra);
6635 if (row) {
6636 new (row) atf_amc::FOptG; // call constructor
6637 row->length = u32(sizeof(atf_amc::FOptG) + nbyte_extra - 0);
6638 if (extra) {
6639 memcpy((u8*)row + sizeof(atf_amc::FOptG), extra, nbyte_extra);
6640 }
6641 }
6642 return row;
6643}
6644
6645// --- atf_amc.FDb.optg.InsertMaybe
6646// Create new row from struct.
6647// Return pointer to new element, or NULL if insertion failed (due to out-of-memory, duplicate key, etc)
6648atf_amc::FOptG* atf_amc::optg_InsertMaybe(const atf_amc::OptG &value) {
6649 u8 *addon_addr = (u8*)&value + ssizeof(atf_amc::OptG);
6650 int addon_len = i32(value.length) - ssizeof(atf_amc::OptG);
6651 atf_amc::FOptG *row = &optg_AllocExtra(addon_addr, addon_len);
6652 optg_CopyIn(*row,const_cast<atf_amc::OptG&>(value));
6653 bool ok = optg_XrefMaybe(*row); // this may return false
6654 if (!ok) {
6655 optg_Delete(*row); // delete offending row, any existing xrefs are cleared
6656 row = NULL; // forget this ever happened
6657 }
6658 return row;
6659}
6660
6661// --- atf_amc.FDb.optg.Delete
6662// Remove row from all global and cross indices, then deallocate row
6663void atf_amc::optg_Delete(atf_amc::FOptG &row) {
6664 int length = i32(row.length);
6665 row.~FOptG();
6666 optg_FreeMem(&row, length);
6667}
6668
6669// --- atf_amc.FDb.optg.XrefMaybe
6670// Insert row into all appropriate indices. If error occurs, store error
6671// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
6672bool atf_amc::optg_XrefMaybe(atf_amc::FOptG &row) {
6673 bool retval = true;
6674 (void)row;
6675 return retval;
6676}
6677
6678// --- atf_amc.FDb.c_typek.Insert
6679// Insert pointer to row into array. Row must not already be in array.
6680// If pointer is already in the array, it may be inserted twice.
6681void atf_amc::c_typek_Insert(atf_amc::FTypeK& row) {
6682 if (bool_Update(row._db_c_typek_in_ary,true)) {
6683 // reserve space
6684 c_typek_Reserve(1);
6685 u32 n = _db.c_typek_n;
6686 u32 at = n;
6687 atf_amc::FTypeK* *elems = _db.c_typek_elems;
6688 elems[at] = &row;
6689 _db.c_typek_n = n+1;
6690
6691 }
6692}
6693
6694// --- atf_amc.FDb.c_typek.InsertMaybe
6695// Insert pointer to row in array.
6696// If row is already in the array, do nothing.
6697// Return value: whether element was inserted into array.
6698bool atf_amc::c_typek_InsertMaybe(atf_amc::FTypeK& row) {
6699 bool retval = !row._db_c_typek_in_ary;
6700 c_typek_Insert(row); // check is performed in _Insert again
6701 return retval;
6702}
6703
6704// --- atf_amc.FDb.c_typek.Remove
6705// Find element using linear scan. If element is in array, remove, otherwise do nothing
6706void atf_amc::c_typek_Remove(atf_amc::FTypeK& row) {
6707 if (bool_Update(row._db_c_typek_in_ary,false)) {
6708 int lim = _db.c_typek_n;
6709 atf_amc::FTypeK* *elems = _db.c_typek_elems;
6710 // search backward, so that most recently added element is found first.
6711 // if found, shift array.
6712 for (int i = lim-1; i>=0; i--) {
6713 atf_amc::FTypeK* elem = elems[i]; // fetch element
6714 if (elem == &row) {
6715 int j = i + 1;
6716 size_t nbytes = sizeof(atf_amc::FTypeK*) * (lim - j);
6717 memmove(elems + i, elems + j, nbytes);
6718 _db.c_typek_n = lim - 1;
6719 break;
6720 }
6721 }
6722 }
6723}
6724
6725// --- atf_amc.FDb.c_typek.Reserve
6726// Reserve space in index for N more elements;
6727void atf_amc::c_typek_Reserve(u32 n) {
6728 u32 old_max = _db.c_typek_max;
6729 if (UNLIKELY(_db.c_typek_n + n > old_max)) {
6730 u32 new_max = u32_Max(4, old_max * 2);
6731 u32 old_size = old_max * sizeof(atf_amc::FTypeK*);
6732 u32 new_size = new_max * sizeof(atf_amc::FTypeK*);
6733 void *new_mem = algo_lib::malloc_ReallocMem(_db.c_typek_elems, old_size, new_size);
6734 if (UNLIKELY(!new_mem)) {
6735 FatalErrorExit("atf_amc.out_of_memory field:atf_amc.FDb.c_typek");
6736 }
6737 _db.c_typek_elems = (atf_amc::FTypeK**)new_mem;
6738 _db.c_typek_max = new_max;
6739 }
6740}
6741
6742// --- atf_amc.FDb.avl.Alloc
6743// Allocate memory for new default row.
6744// If out of memory, process is killed.
6745atf_amc::FAvl& atf_amc::avl_Alloc() {
6746 atf_amc::FAvl* row = avl_AllocMaybe();
6747 if (UNLIKELY(row == NULL)) {
6748 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.FDb.avl comment:'Alloc failed'");
6749 }
6750 return *row;
6751}
6752
6753// --- atf_amc.FDb.avl.AllocMaybe
6754// Allocate memory for new element. If out of memory, return NULL.
6755atf_amc::FAvl* atf_amc::avl_AllocMaybe() {
6756 atf_amc::FAvl *row = (atf_amc::FAvl*)avl_AllocMem();
6757 if (row) {
6758 new (row) atf_amc::FAvl; // call constructor
6759 }
6760 return row;
6761}
6762
6763// --- atf_amc.FDb.avl.AllocMem
6764// Allocate space for one element. If no memory available, return NULL.
6765void* atf_amc::avl_AllocMem() {
6766 u64 new_nelems = _db.avl_n+1;
6767 // compute level and index on level
6768 u64 bsr = algo::u64_BitScanReverse(new_nelems);
6769 u64 base = u64(1)<<bsr;
6770 u64 index = new_nelems-base;
6771 void *ret = NULL;
6772 // if level doesn't exist yet, create it
6773 atf_amc::FAvl* lev = NULL;
6774 if (bsr < 32) {
6775 lev = _db.avl_lary[bsr];
6776 if (!lev) {
6777 lev=(atf_amc::FAvl*)algo_lib::malloc_AllocMem(sizeof(atf_amc::FAvl) * (u64(1)<<bsr));
6778 _db.avl_lary[bsr] = lev;
6779 }
6780 }
6781 // allocate element from this level
6782 if (lev) {
6783 _db.avl_n = i32(new_nelems);
6784 ret = lev + index;
6785 }
6786 return ret;
6787}
6788
6789// --- atf_amc.FDb.avl.RemoveAll
6790// Remove all elements from Lary
6791void atf_amc::avl_RemoveAll() {
6792 for (u64 n = _db.avl_n; n>0; ) {
6793 n--;
6794 avl_qFind(u64(n)).~FAvl(); // destroy last element
6795 _db.avl_n = i32(n);
6796 }
6797}
6798
6799// --- atf_amc.FDb.avl.RemoveLast
6800// Delete last element of array. Do nothing if array is empty.
6801void atf_amc::avl_RemoveLast() {
6802 u64 n = _db.avl_n;
6803 if (n > 0) {
6804 n -= 1;
6805 avl_qFind(u64(n)).~FAvl();
6806 _db.avl_n = i32(n);
6807 }
6808}
6809
6810// --- atf_amc.FDb.avl.XrefMaybe
6811// Insert row into all appropriate indices. If error occurs, store error
6812// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
6813bool atf_amc::avl_XrefMaybe(atf_amc::FAvl &row) {
6814 bool retval = true;
6815 (void)row;
6816 return retval;
6817}
6818
6819// --- atf_amc.FDb.tr_avl.FirstImpl
6820atf_amc::FAvl* atf_amc::tr_avl_FirstImpl(atf_amc::FAvl* root) {
6821 atf_amc::FAvl *result = root;
6822 while(result != NULL && result->tr_avl_left != NULL){
6823 result = result->tr_avl_left;
6824 }
6825 return result;
6826}
6827
6828// --- atf_amc.FDb.tr_avl.First
6829// Return pointer to the first(smallest) element in the tree
6830atf_amc::FAvl* atf_amc::tr_avl_First() {
6831 return tr_avl_FirstImpl(_db.tr_avl_root);
6832}
6833
6834// --- atf_amc.FDb.tr_avl.InsertImpl
6835// Insert row into the tree. If row is already in the tree, do nothing.
6836void atf_amc::tr_avl_InsertImpl(atf_amc::FAvl* parent, atf_amc::FAvl& row) {
6837 bool left = false;
6838 while(parent != NULL){
6839 left = tr_avl_ElemLt(row, *parent);
6840 atf_amc::FAvl* side = left ? parent->tr_avl_left : parent->tr_avl_right;
6841 if(side == NULL){
6842 break;
6843 }
6844 parent = side;
6845 }
6846 tr_avl_Connect(parent, &row, left);
6847}
6848
6849// --- atf_amc.FDb.tr_avl.Insert
6850// Insert row into the tree. If row is already in the tree, do nothing.
6851void atf_amc::tr_avl_Insert(atf_amc::FAvl& row) {
6852 if(!tr_avl_InTreeQ(row)){
6853 _db.tr_avl_n++;
6854 tr_avl_InsertImpl(_db.tr_avl_root, row);
6855 _db.tr_avl_root = tr_avl_Propagate(row);
6856 }
6857}
6858
6859// --- atf_amc.FDb.tr_avl.Remove
6860// Remove element from index. If element is not in index, do nothing.
6861void atf_amc::tr_avl_Remove(atf_amc::FAvl& row) {
6862 if(!tr_avl_InTreeQ(row)){
6863 return;
6864 }
6865 atf_amc::FAvl* next = NULL;
6866 if(row.tr_avl_depth > 1){
6867 next = tr_avl_Balance(row) < 0 ? tr_avl_FirstImpl(row.tr_avl_right) : tr_avl_LastImpl(row.tr_avl_left);
6868 atf_amc::FAvl* leaf = tr_avl_TallerChild(*next);
6869 if(leaf){
6870 tr_avl_Turn(*leaf, *next);
6871 }
6872 }
6873 atf_amc::FAvl* root = row.tr_avl_up;
6874 atf_amc::FAvl* prop = root;//propagate point
6875 if(next){
6876 prop = next->tr_avl_up == &row ? next : next->tr_avl_up;
6877 tr_avl_Disconnect(*next);
6878 tr_avl_Connect(next, row.tr_avl_left, true);
6879 tr_avl_Connect(next, row.tr_avl_right, false);
6880 }
6881 bool dir = root && root->tr_avl_left == &row;
6882 tr_avl_Connect(root, next, dir);
6883 _db.tr_avl_root = prop ? tr_avl_Propagate(*prop) : NULL;
6884 row.tr_avl_depth = 0;
6885 row.tr_avl_left = NULL;
6886 row.tr_avl_right = NULL;
6887 row.tr_avl_up = (atf_amc::FAvl*)-1;
6888 _db.tr_avl_n--;
6889}
6890
6891// --- atf_amc.FDb.tr_avl.RemoveFirst
6892// If the tree is empty, return NULL. Otherwise unlink and return pointer to first element.
6893void atf_amc::tr_avl_RemoveFirst() {
6894 if(!tr_avl_EmptyQ()){
6895 tr_avl_Remove(*tr_avl_First());
6896 }
6897}
6898
6899// --- atf_amc.FDb.tr_avl.Balance
6900i32 atf_amc::tr_avl_Balance(atf_amc::FAvl& row) {
6901 i32 left = row.tr_avl_left ? row.tr_avl_left->tr_avl_depth : 0;
6902 i32 right = row.tr_avl_right ? row.tr_avl_right->tr_avl_depth : 0;
6903 return left - right;
6904}
6905
6906// --- atf_amc.FDb.tr_avl.Propagate
6907// Recalculate depth and keep rebalancing if needed
6908atf_amc::FAvl* atf_amc::tr_avl_Propagate(atf_amc::FAvl& pnode) {
6909 atf_amc::FAvl *root = &pnode;
6910 atf_amc::FAvl* node = &pnode;
6911 while(node != NULL){
6912 tr_avl_updateDepth(*node);
6913 tr_avl_Rebalance(*node);
6914 root = node;
6915 node = node->tr_avl_up;
6916 }
6917 return root;
6918}
6919
6920// --- atf_amc.FDb.tr_avl.TallerChild
6921// Returns the child that has greater height.
6922inline static atf_amc::FAvl* atf_amc::tr_avl_TallerChild(atf_amc::FAvl& node) {
6923 return tr_avl_Balance(node) < 0 ? node.tr_avl_right : node.tr_avl_left;
6924}
6925
6926// --- atf_amc.FDb.tr_avl.Disconnect
6927// Disconnects the subtree(branch) from the parent
6928static void atf_amc::tr_avl_Disconnect(atf_amc::FAvl& node) {
6929 atf_amc::FAvl* parent = node.tr_avl_up;
6930 if(parent != NULL){
6931 bool left = parent->tr_avl_left == &node;
6932 (left ? parent->tr_avl_left : parent->tr_avl_right) = NULL;
6933 }
6934 node.tr_avl_up = NULL;
6935}
6936
6937// --- atf_amc.FDb.tr_avl.Rebalance
6938// Rebalances the node if needed.
6939void atf_amc::tr_avl_Rebalance(atf_amc::FAvl& node) {
6940 if (algo::Abs(tr_avl_Balance(node)) > 1){
6941 atf_amc::FAvl* deep1 = tr_avl_TallerChild(node);
6942 atf_amc::FAvl* deep2 = tr_avl_TallerChild(*deep1);
6943 bool turn = tr_avl_Balance(*deep1)!=0 && (node.tr_avl_left == deep1) != (deep1->tr_avl_left == deep2);
6944 if(turn){
6945 tr_avl_Turn(*deep2, *deep1);
6946 algo::TSwap(deep1, deep2);
6947 }
6948 tr_avl_Turn(*deep1, node);
6949 tr_avl_updateDepth(node);
6950 tr_avl_updateDepth(*deep2);
6951 tr_avl_updateDepth(*deep1);
6952 }
6953}
6954
6955// --- atf_amc.FDb.tr_avl.Next
6956atf_amc::FAvl* atf_amc::tr_avl_Next(atf_amc::FAvl& node) {
6957 atf_amc::FAvl *result = &node;
6958 if(result->tr_avl_right == NULL){
6959 while(result->tr_avl_up != NULL && result->tr_avl_up->tr_avl_right == result){
6960 result = result->tr_avl_up;
6961 }
6962 result = result->tr_avl_up;
6963 }else{
6964 result = tr_avl_FirstImpl(result->tr_avl_right);
6965 }
6966 return result;
6967}
6968
6969// --- atf_amc.FDb.tr_avl.Prev
6970atf_amc::FAvl* atf_amc::tr_avl_Prev(atf_amc::FAvl& node) {
6971 atf_amc::FAvl *result = &node;
6972 if(result->tr_avl_left == NULL){
6973 while(result->tr_avl_up != NULL && result->tr_avl_up->tr_avl_left == result){
6974 result = result->tr_avl_up;
6975 }
6976 result = result->tr_avl_up;
6977 }else{
6978 result = tr_avl_LastImpl(result->tr_avl_left);
6979 }
6980 return result;
6981}
6982
6983// --- atf_amc.FDb.tr_avl.LastImpl
6984atf_amc::FAvl* atf_amc::tr_avl_LastImpl(atf_amc::FAvl* root) {
6985 atf_amc::FAvl *result = root;
6986 while(result != NULL && result->tr_avl_right != NULL){
6987 result = result->tr_avl_right;
6988 }
6989 return result;
6990}
6991
6992// --- atf_amc.FDb.tr_avl.Last
6993// Return pointer to the last(largest) element in tree
6994atf_amc::FAvl* atf_amc::tr_avl_Last() {
6995 return tr_avl_LastImpl(_db.tr_avl_root);
6996}
6997
6998// --- atf_amc.FDb.tr_avl.ElemLt
6999inline static bool atf_amc::tr_avl_ElemLt(atf_amc::FAvl &a, atf_amc::FAvl &b) {
7000 (void)_db;
7001 return a.n < b.n;
7002}
7003
7004// --- atf_amc.FDb.tr_avl.UpdateDepth
7005static void atf_amc::tr_avl_updateDepth(atf_amc::FAvl& node) {
7006 i32 ldepth = node.tr_avl_left != NULL ? node.tr_avl_left->tr_avl_depth : 0;
7007 i32 rdepth = node.tr_avl_right != NULL ? node.tr_avl_right->tr_avl_depth : 0;
7008 node.tr_avl_depth = i32_Max(ldepth, rdepth) + 1;
7009}
7010
7011// --- atf_amc.FDb.tr_avl.Turn
7012// rotates the tree in from->to direction
7013static void atf_amc::tr_avl_Turn(atf_amc::FAvl& from, atf_amc::FAvl& to) {
7014 atf_amc::FAvl* root = to.tr_avl_up;
7015 bool dir = root && root->tr_avl_left == &to;
7016 tr_avl_Connect(root, &from, dir);
7017 dir = to.tr_avl_left == &from;
7018 atf_amc::FAvl* orphan = (dir ? from.tr_avl_right : from.tr_avl_left);//other side
7019 tr_avl_Connect(&from, &to , !dir);
7020 tr_avl_Connect(&to, orphan, dir);
7021}
7022
7023// --- atf_amc.FDb.tr_avl.Connect
7024inline static void atf_amc::tr_avl_Connect(atf_amc::FAvl* parent, atf_amc::FAvl* child, bool left) {
7025 if(parent){
7026 (left ? parent->tr_avl_left : parent->tr_avl_right) = child;
7027 }
7028 if(child){
7029 child->tr_avl_up = parent;
7030 }
7031}
7032
7033// --- atf_amc.FDb.tr_avl.RemoveAllImpl
7034// Empty the index. (rows may be deleted if cascdel)
7035void atf_amc::tr_avl_RemoveAllImpl(atf_amc::FAvl* root, bool del) {
7036 if(root != NULL){
7037 tr_avl_RemoveAllImpl(root->tr_avl_left, del);
7038 tr_avl_RemoveAllImpl(root->tr_avl_right, del);
7039 tr_avl_Disconnect(*root);
7040 root->tr_avl_depth = 0;//the pointers are taken care of by Disconnect
7041 root->tr_avl_up = (atf_amc::FAvl*)-1;//the pointers are taken care of by Disconnect
7042 }
7043}
7044
7045// --- atf_amc.FDb.tr_avl.Reinsert
7046// Reinsert a row with modified key(Reheap semantics)
7047void atf_amc::tr_avl_Reinsert(atf_amc::FAvl& node) {
7048 tr_avl_Remove(node);
7049 tr_avl_Insert(node);
7050}
7051
7052// --- atf_amc.FDb.tr_avl.FirstGe
7053// Find the first element that is greater or equal to a sortfld value
7054atf_amc::FAvl* atf_amc::tr_avl_FirstGe(const i32& val) {
7055 atf_amc::FAvl* result = _db.tr_avl_root;
7056 bool left = false;
7057 while(result){
7058 left = !((*result).n < val);
7059 atf_amc::FAvl* side = left ? result->tr_avl_left : result->tr_avl_right;
7060 if(side==NULL){
7061 break;
7062 }
7063 result = side;
7064 }
7065 while(result && (*result).n < val){
7066 result = tr_avl_Next(*result);
7067 }
7068 return result;
7069}
7070
7071// --- atf_amc.FDb.tr_avl.LastLt
7072// Find the last element that is smaller or equal to a sortfld value
7073atf_amc::FAvl* atf_amc::tr_avl_LastLt(const i32& val) {
7074 atf_amc::FAvl* result = _db.tr_avl_root;
7075 bool left = false;
7076 while(result){
7077 left = val < (*result).n;
7078 atf_amc::FAvl* side = left ? result->tr_avl_left : result->tr_avl_right;
7079 if(side==NULL){
7080 break;
7081 }
7082 result = side;
7083 }
7084 while(result && !((*result).n < val)){
7085 result = tr_avl_Prev(*result);
7086 }
7087 return result;
7088}
7089
7090// --- atf_amc.FDb.listtype.Alloc
7091// Allocate memory for new default row.
7092// If out of memory, process is killed.
7093atf_amc::FListtype& atf_amc::listtype_Alloc() {
7094 atf_amc::FListtype* row = listtype_AllocMaybe();
7095 if (UNLIKELY(row == NULL)) {
7096 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.FDb.listtype comment:'Alloc failed'");
7097 }
7098 return *row;
7099}
7100
7101// --- atf_amc.FDb.listtype.AllocMaybe
7102// Allocate memory for new element. If out of memory, return NULL.
7103atf_amc::FListtype* atf_amc::listtype_AllocMaybe() {
7104 atf_amc::FListtype *row = (atf_amc::FListtype*)listtype_AllocMem();
7105 if (row) {
7106 new (row) atf_amc::FListtype; // call constructor
7107 }
7108 return row;
7109}
7110
7111// --- atf_amc.FDb.listtype.InsertMaybe
7112// Create new row from struct.
7113// Return pointer to new element, or NULL if insertion failed (due to out-of-memory, duplicate key, etc)
7114atf_amc::FListtype* atf_amc::listtype_InsertMaybe(const dmmeta::Listtype &value) {
7115 atf_amc::FListtype *row = &listtype_Alloc(); // if out of memory, process dies. if input error, return NULL.
7116 listtype_CopyIn(*row,const_cast<dmmeta::Listtype&>(value));
7117 bool ok = listtype_XrefMaybe(*row); // this may return false
7118 if (!ok) {
7119 listtype_RemoveLast(); // delete offending row, any existing xrefs are cleared
7120 row = NULL; // forget this ever happened
7121 }
7122 return row;
7123}
7124
7125// --- atf_amc.FDb.listtype.RemoveAll
7126// Destroy all elements of Inlary
7127void atf_amc::listtype_RemoveAll() {
7128 for (u64 n = _db.listtype_n; n>0; ) {
7129 n--;
7130 reinterpret_cast<atf_amc::FListtype*>(_db.listtype_data)[n].~FListtype(); // destroy last element
7131 _db.listtype_n=n;
7132 }
7133}
7134
7135// --- atf_amc.FDb.listtype.RemoveLast
7136// Delete last element of array. Do nothing if array is empty.
7137void atf_amc::listtype_RemoveLast() {
7138 u64 n = _db.listtype_n;
7139 if (n > 0) {
7140 n -= 1;
7141 reinterpret_cast<atf_amc::FListtype*>(_db.listtype_data)[n].~FListtype();
7142 _db.listtype_n = n;
7143 }
7144}
7145
7146// --- atf_amc.FDb.listtype.LoadStatic
7147static void atf_amc::listtype_LoadStatic() {
7148 static struct _t {
7149 const char *s;
7150 void (*step)(atf_amc::FListtype&);
7151 } data[] = {
7152 { "dmmeta.listtype listtype:cd circular:Y haveprev:Y instail:Y comment:\"Circular doubly-linked queue\"", atf_amc::listtype_cd }
7153 ,{ "dmmeta.listtype listtype:cdl circular:Y haveprev:Y instail:N comment:\"Circular double-linked lifo (stack)\"", atf_amc::listtype_cdl }
7154 ,{ "dmmeta.listtype listtype:cs circular:Y haveprev:N instail:Y comment:\"Circular singly-linked queue\"", atf_amc::listtype_cs }
7155 ,{ "dmmeta.listtype listtype:csl circular:Y haveprev:N instail:N comment:\"Circular singly-linked lifo (stack)\"", atf_amc::listtype_csl }
7156 ,{ "dmmeta.listtype listtype:zd circular:N haveprev:Y instail:Y comment:\"Zero-terminated doubly-linked queue\"", atf_amc::listtype_zd }
7157 ,{ "dmmeta.listtype listtype:zdl circular:N haveprev:Y instail:N comment:\"Zero-terminated doubly-linked lifo (stack)\"", atf_amc::listtype_zdl }
7158 ,{ "dmmeta.listtype listtype:zs circular:N haveprev:N instail:Y comment:\"Zero-terminated singly-linked queue\"", atf_amc::listtype_zs }
7159 ,{ "dmmeta.listtype listtype:zsl circular:N haveprev:N instail:N comment:\"Zero-terminated singly-linked lifo (stack)\"", atf_amc::listtype_zsl }
7160 ,{NULL, NULL}
7161 };
7162 (void)data;
7163 dmmeta::Listtype listtype;
7164 for (int i=0; data[i].s; i++) {
7165 (void)dmmeta::Listtype_ReadStrptrMaybe(listtype, algo::strptr(data[i].s));
7166 atf_amc::FListtype *elem = listtype_InsertMaybe(listtype);
7167 vrfy(elem, tempstr("atf_amc.static_insert_fatal_error")
7168 << Keyval("tuple",algo::strptr(data[i].s))
7169 << Keyval("comment",algo_lib::DetachBadTags()));
7170 elem->step = data[i].step;
7171 }
7172}
7173
7174// --- atf_amc.FDb.listtype.XrefMaybe
7175// Insert row into all appropriate indices. If error occurs, store error
7176// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
7177bool atf_amc::listtype_XrefMaybe(atf_amc::FListtype &row) {
7178 bool retval = true;
7179 (void)row;
7180 return retval;
7181}
7182
7183// --- atf_amc.FDb.typed.Alloc
7184// Allocate memory for new default row.
7185// If out of memory, process is killed.
7186atf_amc::FTypeD& atf_amc::typed_Alloc() {
7187 atf_amc::FTypeD* row = typed_AllocMaybe();
7188 if (UNLIKELY(row == NULL)) {
7189 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.FDb.typed comment:'Alloc failed'");
7190 }
7191 return *row;
7192}
7193
7194// --- atf_amc.FDb.typed.AllocMaybe
7195// Allocate memory for new element. If out of memory, return NULL.
7196atf_amc::FTypeD* atf_amc::typed_AllocMaybe() {
7197 atf_amc::FTypeD *row = (atf_amc::FTypeD*)typed_AllocMem();
7198 if (row) {
7199 new (row) atf_amc::FTypeD; // call constructor
7200 }
7201 return row;
7202}
7203
7204// --- atf_amc.FDb.typed.InsertMaybe
7205// Create new row from struct.
7206// Return pointer to new element, or NULL if insertion failed (due to out-of-memory, duplicate key, etc)
7207atf_amc::FTypeD* atf_amc::typed_InsertMaybe(const atf_amc::TypeC &value) {
7208 atf_amc::FTypeD *row = &typed_Alloc(); // if out of memory, process dies. if input error, return NULL.
7209 typed_CopyIn(*row,const_cast<atf_amc::TypeC&>(value));
7210 bool ok = typed_XrefMaybe(*row); // this may return false
7211 if (!ok) {
7212 typed_Delete(*row); // delete offending row, any existing xrefs are cleared
7213 row = NULL; // forget this ever happened
7214 }
7215 return row;
7216}
7217
7218// --- atf_amc.FDb.typed.Delete
7219// Remove row from all global and cross indices, then deallocate row
7220void atf_amc::typed_Delete(atf_amc::FTypeD &row) {
7221 row.~FTypeD();
7222 typed_FreeMem(row);
7223}
7224
7225// --- atf_amc.FDb.typed.AllocMem
7226// Allocate space for one element
7227// If no memory available, return NULL.
7228void* atf_amc::typed_AllocMem() {
7229 atf_amc::FTypeD *row = _db.typed_free;
7230 if (UNLIKELY(!row)) {
7231 typed_Reserve(1);
7232 row = _db.typed_free;
7233 }
7234 if (row) {
7235 _db.typed_free = row->typed_next;
7236 }
7237 return row;
7238}
7239
7240// --- atf_amc.FDb.typed.FreeMem
7241// Remove mem from all global and cross indices, then deallocate mem
7242void atf_amc::typed_FreeMem(atf_amc::FTypeD &row) {
7243 if (UNLIKELY(row.typed_next != (atf_amc::FTypeD*)-1)) {
7244 FatalErrorExit("atf_amc.tpool_double_delete pool:atf_amc.FDb.typed comment:'double deletion caught'");
7245 }
7246 row.typed_next = _db.typed_free; // insert into free list
7247 _db.typed_free = &row;
7248}
7249
7250// --- atf_amc.FDb.typed.Reserve
7251// Preallocate memory for N more elements
7252// Return number of elements actually reserved.
7253u64 atf_amc::typed_Reserve(u64 n_elems) {
7254 u64 ret = 0;
7255 while (ret < n_elems) {
7256 u64 size = _db.typed_blocksize; // underlying allocator is probably Lpool
7257 u64 reserved = typed_ReserveMem(size);
7258 ret += reserved;
7259 if (reserved == 0) {
7260 break;
7261 }
7262 }
7263 return ret;
7264}
7265
7266// --- atf_amc.FDb.typed.ReserveMem
7267// Allocate block of given size, break up into small elements and append to free list.
7268// Return number of elements reserved.
7269u64 atf_amc::typed_ReserveMem(u64 size) {
7270 u64 ret = 0;
7271 if (size >= sizeof(atf_amc::FTypeD)) {
7272 atf_amc::FTypeD *mem = (atf_amc::FTypeD*)algo_lib::malloc_AllocMem(size);
7273 ret = mem ? size / sizeof(atf_amc::FTypeD) : 0;
7274 // add newly allocated elements to the free list;
7275 for (u64 i=0; i < ret; i++) {
7276 mem[i].typed_next = _db.typed_free;
7277 _db.typed_free = mem+i;
7278 }
7279 }
7280 return ret;
7281}
7282
7283// --- atf_amc.FDb.typed.XrefMaybe
7284// Insert row into all appropriate indices. If error occurs, store error
7285// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
7286bool atf_amc::typed_XrefMaybe(atf_amc::FTypeD &row) {
7287 bool retval = true;
7288 (void)row;
7289 // insert typed into index zd_typed
7290 if (true) { // user-defined insert condition
7291 zd_typed_Insert(row);
7292 }
7293 // insert typed into index zs_t_typed
7294 if (true) { // user-defined insert condition
7295 zs_t_typed_Insert(row);
7296 }
7297 // insert typed into index cd_typed
7298 if (true) { // user-defined insert condition
7299 cd_typed_Insert(row);
7300 }
7301 return retval;
7302}
7303
7304// --- atf_amc.FDb.bytebuf_dyn.XrefMaybe
7305// Insert row into all appropriate indices. If error occurs, store error
7306// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
7307bool atf_amc::bytebuf_dyn_XrefMaybe(atf_amc::BytebufDyn &row) {
7308 bool retval = true;
7309 (void)row;
7310 return retval;
7311}
7312
7313// --- atf_amc.FDb.ind_thash_elem.Find
7314// Find row by key. Return NULL if not found.
7315atf_amc::FThashElem* atf_amc::ind_thash_elem_Find(u64 key) {
7316 u32 index = ::u64_Hash(0, key) & (_db.ind_thash_elem_buckets_n - 1);
7317 atf_amc::FThashElem* *e = &_db.ind_thash_elem_buckets_elems[index];
7318 atf_amc::FThashElem* ret=NULL;
7319 do {
7320 ret = *e;
7321 bool done = !ret || (*ret).key == key;
7322 if (done) break;
7323 e = &ret->ind_thash_elem_next;
7324 } while (true);
7325 return ret;
7326}
7327
7328// --- atf_amc.FDb.ind_thash_elem.GetOrCreate
7329// Find row by key. If not found, create and x-reference a new row with with this key.
7330atf_amc::FThashElem& atf_amc::ind_thash_elem_GetOrCreate(u64 key) {
7331 atf_amc::FThashElem* ret = ind_thash_elem_Find(key);
7332 if (!ret) { // if memory alloc fails, process dies; if insert fails, function returns NULL.
7333 ret = &thash_elem_Alloc();
7334 (*ret).key = key;
7335 bool good = thash_elem_XrefMaybe(*ret);
7336 if (!good) {
7337 thash_elem_RemoveLast(); // delete offending row, any existing xrefs are cleared
7338 ret = NULL;
7339 }
7340 }
7341 vrfy(ret, tempstr() << "atf_amc.create_error table:ind_thash_elem key:'"<<key<<"' comment:'bad xref'");
7342 return *ret;
7343}
7344
7345// --- atf_amc.FDb.ind_thash_elem.InsertMaybe
7346// Insert row into hash table. Return true if row is reachable through the hash after the function completes.
7347bool atf_amc::ind_thash_elem_InsertMaybe(atf_amc::FThashElem& row) {
7348 ind_thash_elem_Reserve(1);
7349 bool retval = true; // if already in hash, InsertMaybe returns true
7350 if (LIKELY(row.ind_thash_elem_next == (atf_amc::FThashElem*)-1)) {// check if in hash already
7351 u32 index = ::u64_Hash(0, row.key) & (_db.ind_thash_elem_buckets_n - 1);
7352 atf_amc::FThashElem* *prev = &_db.ind_thash_elem_buckets_elems[index];
7353 do {
7354 atf_amc::FThashElem* ret = *prev;
7355 if (!ret) { // exit condition 1: reached the end of the list
7356 break;
7357 }
7358 if ((*ret).key == row.key) { // exit condition 2: found matching key
7359 retval = false;
7360 break;
7361 }
7362 prev = &ret->ind_thash_elem_next;
7363 } while (true);
7364 if (retval) {
7365 row.ind_thash_elem_next = *prev;
7366 _db.ind_thash_elem_n++;
7367 *prev = &row;
7368 }
7369 }
7370 return retval;
7371}
7372
7373// --- atf_amc.FDb.ind_thash_elem.Remove
7374// Remove reference to element from hash index. If element is not in hash, do nothing
7375void atf_amc::ind_thash_elem_Remove(atf_amc::FThashElem& row) {
7376 if (LIKELY(row.ind_thash_elem_next != (atf_amc::FThashElem*)-1)) {// check if in hash already
7377 u32 index = ::u64_Hash(0, row.key) & (_db.ind_thash_elem_buckets_n - 1);
7378 atf_amc::FThashElem* *prev = &_db.ind_thash_elem_buckets_elems[index]; // addr of pointer to current element
7379 while (atf_amc::FThashElem *next = *prev) { // scan the collision chain for our element
7380 if (next == &row) { // found it?
7381 *prev = next->ind_thash_elem_next; // unlink (singly linked list)
7382 _db.ind_thash_elem_n--;
7383 row.ind_thash_elem_next = (atf_amc::FThashElem*)-1;// not-in-hash
7384 break;
7385 }
7386 prev = &next->ind_thash_elem_next;
7387 }
7388 }
7389}
7390
7391// --- atf_amc.FDb.ind_thash_elem.Reserve
7392// Reserve enough room in the hash for N more elements. Return success code.
7393void atf_amc::ind_thash_elem_Reserve(int n) {
7394 u32 old_nbuckets = _db.ind_thash_elem_buckets_n;
7395 u32 new_nelems = _db.ind_thash_elem_n + n;
7396 // # of elements has to be roughly equal to the number of buckets
7397 if (new_nelems > old_nbuckets) {
7398 int new_nbuckets = i32_Max(algo::BumpToPow2(new_nelems), u32(4));
7399 u32 old_size = old_nbuckets * sizeof(atf_amc::FThashElem*);
7400 u32 new_size = new_nbuckets * sizeof(atf_amc::FThashElem*);
7401 // allocate new array. we don't use Realloc since copying is not needed and factor of 2 probably
7402 // means new memory will have to be allocated anyway
7403 atf_amc::FThashElem* *new_buckets = (atf_amc::FThashElem**)algo_lib::malloc_AllocMem(new_size);
7404 if (UNLIKELY(!new_buckets)) {
7405 FatalErrorExit("atf_amc.out_of_memory field:atf_amc.FDb.ind_thash_elem");
7406 }
7407 memset(new_buckets, 0, new_size); // clear pointers
7408 // rehash all entries
7409 for (int i = 0; i < _db.ind_thash_elem_buckets_n; i++) {
7410 atf_amc::FThashElem* elem = _db.ind_thash_elem_buckets_elems[i];
7411 while (elem) {
7412 atf_amc::FThashElem &row = *elem;
7413 atf_amc::FThashElem* next = row.ind_thash_elem_next;
7414 u32 index = ::u64_Hash(0, row.key) & (new_nbuckets-1);
7415 row.ind_thash_elem_next = new_buckets[index];
7416 new_buckets[index] = &row;
7417 elem = next;
7418 }
7419 }
7420 // free old array
7421 algo_lib::malloc_FreeMem(_db.ind_thash_elem_buckets_elems, old_size);
7422 _db.ind_thash_elem_buckets_elems = new_buckets;
7423 _db.ind_thash_elem_buckets_n = new_nbuckets;
7424 }
7425}
7426
7427// --- atf_amc.FDb.ind_thash_elem.FindRemove
7428atf_amc::FThashElem* atf_amc::ind_thash_elem_FindRemove(u64 key) {
7429 u32 index = ::u64_Hash(0, key) & (_db.ind_thash_elem_buckets_n - 1);
7430 atf_amc::FThashElem* *prev = &_db.ind_thash_elem_buckets_elems[index];
7431 atf_amc::FThashElem* ret=NULL;
7432 do {
7433 ret = *prev;
7434 bool done = !ret || (*ret).key == key;
7435 if (done) break;
7436 prev = &ret->ind_thash_elem_next;
7437 } while (true);
7438 if (ret) {
7439 *prev = ret->ind_thash_elem_next;
7440 ret->ind_thash_elem_next = (atf_amc::FThashElem*)-1; // not-in-hash
7441 _db.ind_thash_elem_n--;
7442 }
7443 return ret;
7444}
7445
7446// --- atf_amc.FDb.thash_elem.Alloc
7447// Allocate memory for new default row.
7448// If out of memory, process is killed.
7449atf_amc::FThashElem& atf_amc::thash_elem_Alloc() {
7450 atf_amc::FThashElem* row = thash_elem_AllocMaybe();
7451 if (UNLIKELY(row == NULL)) {
7452 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.FDb.thash_elem comment:'Alloc failed'");
7453 }
7454 return *row;
7455}
7456
7457// --- atf_amc.FDb.thash_elem.AllocMaybe
7458// Allocate memory for new element. If out of memory, return NULL.
7459atf_amc::FThashElem* atf_amc::thash_elem_AllocMaybe() {
7460 atf_amc::FThashElem *row = (atf_amc::FThashElem*)thash_elem_AllocMem();
7461 if (row) {
7462 new (row) atf_amc::FThashElem; // call constructor
7463 }
7464 return row;
7465}
7466
7467// --- atf_amc.FDb.thash_elem.AllocMem
7468// Allocate space for one element. If no memory available, return NULL.
7469void* atf_amc::thash_elem_AllocMem() {
7470 u64 new_nelems = _db.thash_elem_n+1;
7471 // compute level and index on level
7472 u64 bsr = algo::u64_BitScanReverse(new_nelems);
7473 u64 base = u64(1)<<bsr;
7474 u64 index = new_nelems-base;
7475 void *ret = NULL;
7476 // if level doesn't exist yet, create it
7477 atf_amc::FThashElem* lev = NULL;
7478 if (bsr < 32) {
7479 lev = _db.thash_elem_lary[bsr];
7480 if (!lev) {
7481 lev=(atf_amc::FThashElem*)algo_lib::malloc_AllocMem(sizeof(atf_amc::FThashElem) * (u64(1)<<bsr));
7482 _db.thash_elem_lary[bsr] = lev;
7483 }
7484 }
7485 // allocate element from this level
7486 if (lev) {
7487 _db.thash_elem_n = i32(new_nelems);
7488 ret = lev + index;
7489 }
7490 return ret;
7491}
7492
7493// --- atf_amc.FDb.thash_elem.RemoveAll
7494// Remove all elements from Lary
7495void atf_amc::thash_elem_RemoveAll() {
7496 for (u64 n = _db.thash_elem_n; n>0; ) {
7497 n--;
7498 thash_elem_qFind(u64(n)).~FThashElem(); // destroy last element
7499 _db.thash_elem_n = i32(n);
7500 }
7501}
7502
7503// --- atf_amc.FDb.thash_elem.RemoveLast
7504// Delete last element of array. Do nothing if array is empty.
7505void atf_amc::thash_elem_RemoveLast() {
7506 u64 n = _db.thash_elem_n;
7507 if (n > 0) {
7508 n -= 1;
7509 thash_elem_qFind(u64(n)).~FThashElem();
7510 _db.thash_elem_n = i32(n);
7511 }
7512}
7513
7514// --- atf_amc.FDb.thash_elem.XrefMaybe
7515// Insert row into all appropriate indices. If error occurs, store error
7516// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
7517bool atf_amc::thash_elem_XrefMaybe(atf_amc::FThashElem &row) {
7518 bool retval = true;
7519 (void)row;
7520 // insert thash_elem into index ind_thash_elem
7521 if (true) { // user-defined insert condition
7522 bool success = ind_thash_elem_InsertMaybe(row);
7523 if (UNLIKELY(!success)) {
7524 ch_RemoveAll(algo_lib::_db.errtext);
7525 algo_lib::_db.errtext << "atf_amc.duplicate_key xref:atf_amc.FDb.ind_thash_elem"; // check for duplicate key
7526 return false;
7527 }
7528 }
7529 return retval;
7530}
7531
7532// --- atf_amc.FDb.trace.RowidFind
7533// find trace by row id (used to implement reflection)
7534static algo::ImrowPtr atf_amc::trace_RowidFind(int t) {
7535 return algo::ImrowPtr(t==0 ? u64(&_db.trace) : u64(0));
7536}
7537
7538// --- atf_amc.FDb.trace.N
7539// Function return 1
7540inline static i32 atf_amc::trace_N() {
7541 return 1;
7542}
7543
7544// --- atf_amc.FDb.bh_typec_curs.Add
7545static void atf_amc::_db_bh_typec_curs_Add(_db_bh_typec_curs &curs, atf_amc::FTypeC& row) {
7546 u32 n = curs.temp_n;
7547 int i = n;
7548 curs.temp_n = n+1;
7549 atf_amc::FTypeC* *elems = curs.temp_elems;
7550 while (i>0) {
7551 int j = (i-1)/2;
7552 atf_amc::FTypeC* p = elems[j];
7553 if (!bh_typec_ElemLt(row,*p)) {
7554 break;
7555 }
7556 elems[i]=p;
7557 i=j;
7558 }
7559 elems[i]=&row;
7560}
7561
7562// --- atf_amc.FDb.bh_typec_curs.Reserve
7563void atf_amc::_db_bh_typec_curs_Reserve(_db_bh_typec_curs &curs, int n) {
7564 if (n > curs.temp_max) {
7565 size_t old_size = sizeof(void*) * curs.temp_max;
7566 size_t new_size = sizeof(void*) * bh_typec_N();
7567 curs.temp_elems = (atf_amc::FTypeC**)algo_lib::malloc_ReallocMem(curs.temp_elems, old_size, new_size);
7568 if (!curs.temp_elems) {
7569 algo::FatalErrorExit("atf_amc.cursor_out_of_memory func:atf_amc.FDb.bh_typec_curs.Reserve");
7570 }
7571 curs.temp_max = bh_typec_N();
7572 }
7573}
7574
7575// --- atf_amc.FDb.bh_typec_curs.Reset
7576// Reset cursor. If HEAP is non-empty, add its top element to CURS.
7577void atf_amc::_db_bh_typec_curs_Reset(_db_bh_typec_curs &curs, atf_amc::FDb &parent) {
7578 curs.parent = &parent;
7579 _db_bh_typec_curs_Reserve(curs, bh_typec_N());
7580 curs.temp_n = 0;
7581 if (parent.bh_typec_n > 0) {
7582 atf_amc::FTypeC &first = *parent.bh_typec_elems[0];
7583 curs.temp_elems[0] = &first; // insert first element in heap
7584 curs.temp_n = 1;
7585 }
7586}
7587
7588// --- atf_amc.FDb.bh_typec_curs.Next
7589// Advance cursor.
7590void atf_amc::_db_bh_typec_curs_Next(_db_bh_typec_curs &curs) {
7591 atf_amc::FTypeC* *elems = curs.temp_elems;
7592 int n = curs.temp_n;
7593 if (n > 0) {
7594 // remove top element from heap
7595 atf_amc::FTypeC* dead = elems[0];
7596 int i = 0;
7597 atf_amc::FTypeC* last = curs.temp_elems[n-1];
7598 // downheap last elem
7599 do {
7600 atf_amc::FTypeC* choose = last;
7601 int l = i*2+1;
7602 if (l<n) {
7603 atf_amc::FTypeC* el = elems[l];
7604 int r = l+1;
7605 r -= r==n;
7606 atf_amc::FTypeC* er = elems[r];
7607 if (bh_typec_ElemLt(*er,*el)) {
7608 el = er;
7609 l = r;
7610 }
7611 bool b = bh_typec_ElemLt(*el,*last);
7612 if (b) choose = el;
7613 if (!b) l = n;
7614 }
7615 elems[i] = choose;
7616 i = l;
7617 } while (i < n);
7618 curs.temp_n = n-1;
7619 int index = dead->bh_typec_idx;
7620 i = (index*2+1);
7621 if (i < bh_typec_N()) {
7622 atf_amc::FTypeC &elem = *curs.parent->bh_typec_elems[i];
7623 _db_bh_typec_curs_Add(curs, elem);
7624 }
7625 if (i+1 < bh_typec_N()) {
7626 atf_amc::FTypeC &elem = *curs.parent->bh_typec_elems[i + 1];
7627 _db_bh_typec_curs_Add(curs, elem);
7628 }
7629 }
7630}
7631
7632// --- atf_amc.FDb..Init
7633// Set all fields to initial values.
7634void atf_amc::FDb_Init() {
7635 _db.bh_typec_max = 0; // (atf_amc.FDb.bh_typec)
7636 _db.bh_typec_n = 0; // (atf_amc.FDb.bh_typec)
7637 _db.bh_typec_elems = NULL; // (atf_amc.FDb.bh_typec)
7638 _db.zdl_h_typec_head = NULL; // (atf_amc.FDb.zdl_h_typec)
7639 _db.zdl_h_typec_n = 0; // (atf_amc.FDb.zdl_h_typec)
7640 _db.zdl_h_typec_tail = NULL; // (atf_amc.FDb.zdl_h_typec)
7641 _db.zd_t_typec_head = NULL; // (atf_amc.FDb.zd_t_typec)
7642 _db.zd_t_typec_n = 0; // (atf_amc.FDb.zd_t_typec)
7643 _db.zd_t_typec_tail = NULL; // (atf_amc.FDb.zd_t_typec)
7644 _db.zd_typed_head = NULL; // (atf_amc.FDb.zd_typed)
7645 _db.zd_typed_n = 0; // (atf_amc.FDb.zd_typed)
7646 _db.zd_typed_tail = NULL; // (atf_amc.FDb.zd_typed)
7647 _db.zs_t_typed_head = NULL; // (atf_amc.FDb.zs_t_typed)
7648 _db.zs_t_typed_n = 0; // (atf_amc.FDb.zs_t_typed)
7649 _db.zs_t_typed_tail = NULL; // (atf_amc.FDb.zs_t_typed)
7650 _db.cd_typed_head = NULL; // (atf_amc.FDb.cd_typed)
7651 _db.cd_typed_n = 0; // (atf_amc.FDb.cd_typed)
7652 _db.zsl_h_typec_head = NULL; // (atf_amc.FDb.zsl_h_typec)
7653 _db.zsl_h_typec_n = 0; // (atf_amc.FDb.zsl_h_typec)
7654 _db.zsl_h_typec_tail = NULL; // (atf_amc.FDb.zsl_h_typec)
7655 _db.zs_t_typec_head = NULL; // (atf_amc.FDb.zs_t_typec)
7656 _db.zs_t_typec_n = 0; // (atf_amc.FDb.zs_t_typec)
7657 _db.zs_t_typec_tail = NULL; // (atf_amc.FDb.zs_t_typec)
7658 _db.zs_mt_typec_head = NULL; // (atf_amc.FDb.zs_mt_typec)
7659 _db.zs_mt_typec_mt = NULL; // (atf_amc.FDb.zs_mt_typec)
7660 _db.zdl_hnt_typec_head = NULL; // (atf_amc.FDb.zdl_hnt_typec)
7661 _db.zdl_hnt_typec_n = 0; // (atf_amc.FDb.zdl_hnt_typec)
7662 _db.cdl_h_typec_head = NULL; // (atf_amc.FDb.cdl_h_typec)
7663 _db.cdl_h_typec_n = 0; // (atf_amc.FDb.cdl_h_typec)
7664 _db.cd_t_typec_head = NULL; // (atf_amc.FDb.cd_t_typec)
7665 _db.cd_t_typec_n = 0; // (atf_amc.FDb.cd_t_typec)
7666 _db.csl_h_typec_head = NULL; // (atf_amc.FDb.csl_h_typec)
7667 _db.csl_h_typec_n = 0; // (atf_amc.FDb.csl_h_typec)
7668 _db.csl_h_typec_tail = NULL; // (atf_amc.FDb.csl_h_typec)
7669 _db.cs_t_typec_head = NULL; // (atf_amc.FDb.cs_t_typec)
7670 _db.cs_t_typec_n = 0; // (atf_amc.FDb.cs_t_typec)
7671 _db.cs_t_typec_tail = NULL; // (atf_amc.FDb.cs_t_typec)
7672 // initialize LAry typea (atf_amc.FDb.typea)
7673 _db.typea_n = 0;
7674 memset(_db.typea_lary, 0, sizeof(_db.typea_lary)); // zero out all level pointers
7675 atf_amc::FTypeA* typea_first = (atf_amc::FTypeA*)algo_lib::malloc_AllocMem(sizeof(atf_amc::FTypeA) * (u64(1)<<4));
7676 if (!typea_first) {
7677 FatalErrorExit("out of memory");
7678 }
7679 for (int i = 0; i < 4; i++) {
7680 _db.typea_lary[i] = typea_first;
7681 typea_first += 1ULL<<i;
7682 }
7683 // initialize LAry types (atf_amc.FDb.types)
7684 _db.types_n = 0;
7685 memset(_db.types_lary, 0, sizeof(_db.types_lary)); // zero out all level pointers
7686 atf_amc::FTypeS* types_first = (atf_amc::FTypeS*)algo_lib::malloc_AllocMem(sizeof(atf_amc::FTypeS) * (u64(1)<<4));
7687 if (!types_first) {
7688 FatalErrorExit("out of memory");
7689 }
7690 for (int i = 0; i < 4; i++) {
7691 _db.types_lary[i] = types_first;
7692 types_first += 1ULL<<i;
7693 }
7694 // initialize hash table for atf_amc::FTypeS;
7695 _db.ind_types_n = 0; // (atf_amc.FDb.ind_types)
7696 _db.ind_types_buckets_n = 4; // (atf_amc.FDb.ind_types)
7697 _db.ind_types_buckets_elems = (atf_amc::FTypeS**)algo_lib::malloc_AllocMem(sizeof(atf_amc::FTypeS*)*_db.ind_types_buckets_n); // initial buckets (atf_amc.FDb.ind_types)
7698 if (!_db.ind_types_buckets_elems) {
7699 FatalErrorExit("out of memory"); // (atf_amc.FDb.ind_types)
7700 }
7701 memset(_db.ind_types_buckets_elems, 0, sizeof(atf_amc::FTypeS*)*_db.ind_types_buckets_n); // (atf_amc.FDb.ind_types)
7702 // initialize hash table for atf_amc::FTypeA;
7703 _db.ind_typea_n = 0; // (atf_amc.FDb.ind_typea)
7704 _db.ind_typea_buckets_n = 4; // (atf_amc.FDb.ind_typea)
7705 _db.ind_typea_buckets_elems = (atf_amc::FTypeA**)algo_lib::malloc_AllocMem(sizeof(atf_amc::FTypeA*)*_db.ind_typea_buckets_n); // initial buckets (atf_amc.FDb.ind_typea)
7706 if (!_db.ind_typea_buckets_elems) {
7707 FatalErrorExit("out of memory"); // (atf_amc.FDb.ind_typea)
7708 }
7709 memset(_db.ind_typea_buckets_elems, 0, sizeof(atf_amc::FTypeA*)*_db.ind_typea_buckets_n); // (atf_amc.FDb.ind_typea)
7710 _db.cs_h_count = i32(0);
7711 _db.cs_t_count = i32(0);
7712 _db.zs_h_count = i32(0);
7713 _db.zs_t_count = i32(0);
7714 _db.zs_mt_count = i32(0);
7715 _db.bh_count = i32(0);
7716 // initialize LAry typet (atf_amc.FDb.typet)
7717 _db.typet_n = 0;
7718 memset(_db.typet_lary, 0, sizeof(_db.typet_lary)); // zero out all level pointers
7719 atf_amc::FTypeT* typet_first = (atf_amc::FTypeT*)algo_lib::malloc_AllocMem(sizeof(atf_amc::FTypeT) * (u64(1)<<4));
7720 if (!typet_first) {
7721 FatalErrorExit("out of memory");
7722 }
7723 for (int i = 0; i < 4; i++) {
7724 _db.typet_lary[i] = typet_first;
7725 typet_first += 1ULL<<i;
7726 }
7727 // initialize LAry cstring (atf_amc.FDb.cstring)
7728 _db.cstring_n = 0;
7729 memset(_db.cstring_lary, 0, sizeof(_db.cstring_lary)); // zero out all level pointers
7730 atf_amc::FCstring* cstring_first = (atf_amc::FCstring*)algo_lib::malloc_AllocMem(sizeof(atf_amc::FCstring) * (u64(1)<<4));
7731 if (!cstring_first) {
7732 FatalErrorExit("out of memory");
7733 }
7734 for (int i = 0; i < 4; i++) {
7735 _db.cstring_lary[i] = cstring_first;
7736 cstring_first += 1ULL<<i;
7737 }
7738 // initialize hash table for atf_amc::FCstring;
7739 _db.ind_cstring_n = 0; // (atf_amc.FDb.ind_cstring)
7740 _db.ind_cstring_buckets_n = 4; // (atf_amc.FDb.ind_cstring)
7741 _db.ind_cstring_buckets_elems = (atf_amc::FCstring**)algo_lib::malloc_AllocMem(sizeof(atf_amc::FCstring*)*_db.ind_cstring_buckets_n); // initial buckets (atf_amc.FDb.ind_cstring)
7742 if (!_db.ind_cstring_buckets_elems) {
7743 FatalErrorExit("out of memory"); // (atf_amc.FDb.ind_cstring)
7744 }
7745 memset(_db.ind_cstring_buckets_elems, 0, sizeof(atf_amc::FCstring*)*_db.ind_cstring_buckets_n); // (atf_amc.FDb.ind_cstring)
7746 _db.cd_in_msg_head = NULL; // (atf_amc.FDb.cd_in_msg)
7747 // typeb: initialize Tpool
7748 _db.typeb_free = NULL;
7749 _db.typeb_blocksize = algo::BumpToPow2(64 * sizeof(atf_amc::FTypeB)); // allocate 64-127 elements at a time
7750 // pooledbe64: initialize Tpool
7751 _db.pooledbe64_free = NULL;
7752 _db.pooledbe64_blocksize = algo::BumpToPow2(64 * sizeof(atf_amc::PooledBE64)); // allocate 64-127 elements at a time
7753 memset(_db.varlen_extern_free, 0, sizeof(_db.varlen_extern_free));
7754 _db.varlen_extern_n = 0;
7755 // initialize LAry amctest (atf_amc.FDb.amctest)
7756 _db.amctest_n = 0;
7757 memset(_db.amctest_lary, 0, sizeof(_db.amctest_lary)); // zero out all level pointers
7758 atf_amc::FAmctest* amctest_first = (atf_amc::FAmctest*)algo_lib::malloc_AllocMem(sizeof(atf_amc::FAmctest) * (u64(1)<<4));
7759 if (!amctest_first) {
7760 FatalErrorExit("out of memory");
7761 }
7762 for (int i = 0; i < 4; i++) {
7763 _db.amctest_lary[i] = amctest_first;
7764 amctest_first += 1ULL<<i;
7765 }
7766 // cascdel: initialize Tpool
7767 _db.cascdel_free = NULL;
7768 _db.cascdel_blocksize = algo::BumpToPow2(64 * sizeof(atf_amc::FCascdel)); // allocate 64-127 elements at a time
7769 _db.cascdel_next_key = u32(0);
7770 memset(_db.optalloc_free, 0, sizeof(_db.optalloc_free));
7771 _db.optalloc_n = 0;
7772 memset(_db.varlenalloc_free, 0, sizeof(_db.varlenalloc_free));
7773 _db.varlenalloc_n = 0;
7774 memset(_db.optg_free, 0, sizeof(_db.optg_free));
7775 _db.optg_n = 0;
7776 _db.c_typek_elems = NULL; // (atf_amc.FDb.c_typek)
7777 _db.c_typek_n = 0; // (atf_amc.FDb.c_typek)
7778 _db.c_typek_max = 0; // (atf_amc.FDb.c_typek)
7779 // initialize LAry avl (atf_amc.FDb.avl)
7780 _db.avl_n = 0;
7781 memset(_db.avl_lary, 0, sizeof(_db.avl_lary)); // zero out all level pointers
7782 atf_amc::FAvl* avl_first = (atf_amc::FAvl*)algo_lib::malloc_AllocMem(sizeof(atf_amc::FAvl) * (u64(1)<<4));
7783 if (!avl_first) {
7784 FatalErrorExit("out of memory");
7785 }
7786 for (int i = 0; i < 4; i++) {
7787 _db.avl_lary[i] = avl_first;
7788 avl_first += 1ULL<<i;
7789 }
7790 _db.tr_avl_root = NULL; // (atf_amc.FDb.tr_avl)
7791 _db.tr_avl_n = 0;
7792 _db.listtype_n = 0; // listtype: initialize count
7793 _db.dofork = bool(false);
7794 // typed: initialize Tpool
7795 _db.typed_free = NULL;
7796 _db.typed_blocksize = algo::BumpToPow2(64 * sizeof(atf_amc::FTypeD)); // allocate 64-127 elements at a time
7797 // initialize hash table for atf_amc::FThashElem;
7798 _db.ind_thash_elem_n = 0; // (atf_amc.FDb.ind_thash_elem)
7799 _db.ind_thash_elem_buckets_n = 4; // (atf_amc.FDb.ind_thash_elem)
7800 _db.ind_thash_elem_buckets_elems = (atf_amc::FThashElem**)algo_lib::malloc_AllocMem(sizeof(atf_amc::FThashElem*)*_db.ind_thash_elem_buckets_n); // initial buckets (atf_amc.FDb.ind_thash_elem)
7801 if (!_db.ind_thash_elem_buckets_elems) {
7802 FatalErrorExit("out of memory"); // (atf_amc.FDb.ind_thash_elem)
7803 }
7804 memset(_db.ind_thash_elem_buckets_elems, 0, sizeof(atf_amc::FThashElem*)*_db.ind_thash_elem_buckets_n); // (atf_amc.FDb.ind_thash_elem)
7805 // initialize LAry thash_elem (atf_amc.FDb.thash_elem)
7806 _db.thash_elem_n = 0;
7807 memset(_db.thash_elem_lary, 0, sizeof(_db.thash_elem_lary)); // zero out all level pointers
7808 atf_amc::FThashElem* thash_elem_first = (atf_amc::FThashElem*)algo_lib::malloc_AllocMem(sizeof(atf_amc::FThashElem) * (u64(1)<<4));
7809 if (!thash_elem_first) {
7810 FatalErrorExit("out of memory");
7811 }
7812 for (int i = 0; i < 4; i++) {
7813 _db.thash_elem_lary[i] = thash_elem_first;
7814 thash_elem_first += 1ULL<<i;
7815 }
7816
7817 atf_amc::InitReflection();
7818 amctest_LoadStatic(); // gen:ns_gstatic gstatic:atf_amc.FDb.amctest load atf_amc.FAmctest records
7819 listtype_LoadStatic(); // gen:ns_gstatic gstatic:atf_amc.FDb.listtype load atf_amc.FListtype records
7820}
7821
7822// --- atf_amc.FDb..Uninit
7823void atf_amc::FDb_Uninit() {
7824 atf_amc::FDb &row = _db; (void)row;
7825
7826 // atf_amc.FDb.thash_elem.Uninit (Lary) //
7827 // skip destruction in global scope
7828
7829 // atf_amc.FDb.ind_thash_elem.Uninit (Thash) //
7830 // skip destruction of ind_thash_elem in global scope
7831
7832 // atf_amc.FDb.listtype.Uninit (Inlary) //
7833 // skip destruction in global scope
7834
7835 // atf_amc.FDb.avl.Uninit (Lary) //
7836 // skip destruction in global scope
7837
7838 // atf_amc.FDb.c_typek.Uninit (Ptrary) //
7839 algo_lib::malloc_FreeMem(_db.c_typek_elems, sizeof(atf_amc::FTypeK*)*_db.c_typek_max); // (atf_amc.FDb.c_typek)
7840
7841 // atf_amc.FDb.amctest.Uninit (Lary) //
7842 // skip destruction in global scope
7843
7844 // atf_amc.FDb.ind_cstring.Uninit (Thash) //
7845 // skip destruction of ind_cstring in global scope
7846
7847 // atf_amc.FDb.cstring.Uninit (Lary) //
7848 // skip destruction in global scope
7849
7850 // atf_amc.FDb.typet.Uninit (Lary) //
7851 // skip destruction in global scope
7852
7853 // atf_amc.FDb.ind_typea.Uninit (Thash) //
7854 // skip destruction of ind_typea in global scope
7855
7856 // atf_amc.FDb.ind_types.Uninit (Thash) //
7857 // skip destruction of ind_types in global scope
7858
7859 // atf_amc.FDb.types.Uninit (Lary) //
7860 // skip destruction in global scope
7861
7862 // atf_amc.FDb.typea.Uninit (Lary) //
7863 // skip destruction in global scope
7864
7865 // atf_amc.FDb.bh_typec.Uninit (Bheap) //
7866 // skip destruction in global scope
7867}
7868
7869// --- atf_amc.TypeG..ReadStrptrMaybe
7870// Read fields of atf_amc::TypeG from an ascii string.
7871// The format of the string is the format of the atf_amc::TypeG's only field
7872bool atf_amc::TypeG_ReadStrptrMaybe(atf_amc::TypeG &parent, algo::strptr in_str) {
7873 bool retval = true;
7874 retval = retval && i32_ReadStrptrMaybe(parent.typeg, in_str);
7875 return retval;
7876}
7877
7878// --- atf_amc.TypeG..Print
7879// print string representation of ROW to string STR
7880// cfmt:atf_amc.TypeG.String printfmt:Raw
7881void atf_amc::TypeG_Print(atf_amc::TypeG& row, algo::cstring& str) {
7882 i32_Print(row.typeg, str);
7883}
7884
7885// --- atf_amc.FOptG.optg.CopyOut
7886// Copy fields out of row
7887void atf_amc::optg_CopyOut(atf_amc::FOptG &row, atf_amc::OptG &out) {
7888 // length: field value is computed
7889 // typeg: unknown field type (Opt), skipped
7890 (void)row;//only to avoid -Wunused-parameter
7891 (void)out;//only to avoid -Wunused-parameter
7892}
7893
7894// --- atf_amc.FOptG.optg.CopyIn
7895// Copy fields in to row
7896void atf_amc::optg_CopyIn(atf_amc::FOptG &row, atf_amc::OptG &in) {
7897 // length: field value is computed
7898 // typeg: unknown field reftype (Opt), skipped
7899 (void)row;//only to avoid -Wunused-parameter
7900 (void)in;//only to avoid -Wunused-parameter
7901}
7902
7903// --- atf_amc.FOptG.typeg.Getary
7904// Access optional portion as an array of bytes
7905algo::aryptr<u8> atf_amc::typeg_Getary(atf_amc::FOptG& optg) {
7906 u8 *end = (u8*)&optg + sizeof(atf_amc::FOptG);
7907 return algo::aryptr<u8>(end, i32(optg.length) - ssizeof(atf_amc::FOptG));
7908}
7909
7910// --- atf_amc.FPerfSortString.orig.Addary
7911// Reserve space (this may move memory). Insert N element at the end.
7912// Return aryptr to newly inserted block.
7913// If the RHS argument aliases the array (refers to the same memory), exit program with fatal error.
7914algo::aryptr<atf_amc::Cstr> atf_amc::orig_Addary(atf_amc::FPerfSortString& parent, algo::aryptr<atf_amc::Cstr> rhs) {
7915 bool overlaps = rhs.n_elems>0 && rhs.elems >= parent.orig_elems && rhs.elems < parent.orig_elems + parent.orig_max;
7916 if (UNLIKELY(overlaps)) {
7917 FatalErrorExit("atf_amc.tary_alias field:atf_amc.FPerfSortString.orig comment:'alias error: sub-array is being appended to the whole'");
7918 }
7919 int nnew = rhs.n_elems;
7920 orig_Reserve(parent, nnew); // reserve space
7921 int at = parent.orig_n;
7922 for (int i = 0; i < nnew; i++) {
7923 new (parent.orig_elems + at + i) atf_amc::Cstr(rhs[i]);
7924 parent.orig_n++;
7925 }
7926 return algo::aryptr<atf_amc::Cstr>(parent.orig_elems + at, nnew);
7927}
7928
7929// --- atf_amc.FPerfSortString.orig.Alloc
7930// Reserve space. Insert element at the end
7931// The new element is initialized to a default value
7932atf_amc::Cstr& atf_amc::orig_Alloc(atf_amc::FPerfSortString& parent) {
7933 orig_Reserve(parent, 1);
7934 int n = parent.orig_n;
7935 int at = n;
7936 atf_amc::Cstr *elems = parent.orig_elems;
7937 new (elems + at) atf_amc::Cstr(); // construct new element, default initializer
7938 parent.orig_n = n+1;
7939 return elems[at];
7940}
7941
7942// --- atf_amc.FPerfSortString.orig.AllocAt
7943// Reserve space for new element, reallocating the array if necessary
7944// Insert new element at specified index. Index must be in range or a fatal error occurs.
7945atf_amc::Cstr& atf_amc::orig_AllocAt(atf_amc::FPerfSortString& parent, int at) {
7946 orig_Reserve(parent, 1);
7947 int n = parent.orig_n;
7948 if (UNLIKELY(u64(at) >= u64(n+1))) {
7949 FatalErrorExit("atf_amc.bad_alloc_at field:atf_amc.FPerfSortString.orig comment:'index out of range'");
7950 }
7951 atf_amc::Cstr *elems = parent.orig_elems;
7952 memmove(elems + at + 1, elems + at, (n - at) * sizeof(atf_amc::Cstr));
7953 new (elems + at) atf_amc::Cstr(); // construct element, default initializer
7954 parent.orig_n = n+1;
7955 return elems[at];
7956}
7957
7958// --- atf_amc.FPerfSortString.orig.AllocN
7959// Reserve space. Insert N elements at the end of the array, return pointer to array
7960algo::aryptr<atf_amc::Cstr> atf_amc::orig_AllocN(atf_amc::FPerfSortString& parent, int n_elems) {
7961 orig_Reserve(parent, n_elems);
7962 int old_n = parent.orig_n;
7963 int new_n = old_n + n_elems;
7964 atf_amc::Cstr *elems = parent.orig_elems;
7965 for (int i = old_n; i < new_n; i++) {
7966 new (elems + i) atf_amc::Cstr(); // construct new element, default initialize
7967 }
7968 parent.orig_n = new_n;
7969 return algo::aryptr<atf_amc::Cstr>(elems + old_n, n_elems);
7970}
7971
7972// --- atf_amc.FPerfSortString.orig.Remove
7973// Remove item by index. If index outside of range, do nothing.
7974void atf_amc::orig_Remove(atf_amc::FPerfSortString& parent, u32 i) {
7975 u32 lim = parent.orig_n;
7976 atf_amc::Cstr *elems = parent.orig_elems;
7977 if (i < lim) {
7978 elems[i].~Cstr(); // destroy element
7979 memmove(elems + i, elems + (i + 1), sizeof(atf_amc::Cstr) * (lim - (i + 1)));
7980 parent.orig_n = lim - 1;
7981 }
7982}
7983
7984// --- atf_amc.FPerfSortString.orig.RemoveAll
7985void atf_amc::orig_RemoveAll(atf_amc::FPerfSortString& parent) {
7986 u32 n = parent.orig_n;
7987 while (n > 0) {
7988 n -= 1;
7989 parent.orig_elems[n].~Cstr();
7990 parent.orig_n = n;
7991 }
7992}
7993
7994// --- atf_amc.FPerfSortString.orig.RemoveLast
7995// Delete last element of array. Do nothing if array is empty.
7996void atf_amc::orig_RemoveLast(atf_amc::FPerfSortString& parent) {
7997 u64 n = parent.orig_n;
7998 if (n > 0) {
7999 n -= 1;
8000 orig_qFind(parent, u64(n)).~Cstr();
8001 parent.orig_n = n;
8002 }
8003}
8004
8005// --- atf_amc.FPerfSortString.orig.AbsReserve
8006// Make sure N elements fit in array. Process dies if out of memory
8007void atf_amc::orig_AbsReserve(atf_amc::FPerfSortString& parent, int n) {
8008 u32 old_max = parent.orig_max;
8009 if (n > i32(old_max)) {
8010 u32 new_max = i32_Max(i32_Max(old_max * 2, n), 4);
8011 void *new_mem = algo_lib::malloc_ReallocMem(parent.orig_elems, old_max * sizeof(atf_amc::Cstr), new_max * sizeof(atf_amc::Cstr));
8012 if (UNLIKELY(!new_mem)) {
8013 FatalErrorExit("atf_amc.tary_nomem field:atf_amc.FPerfSortString.orig comment:'out of memory'");
8014 }
8015 parent.orig_elems = (atf_amc::Cstr*)new_mem;
8016 parent.orig_max = new_max;
8017 }
8018}
8019
8020// --- atf_amc.FPerfSortString.orig.Setary
8021// Copy contents of RHS to PARENT.
8022void atf_amc::orig_Setary(atf_amc::FPerfSortString& parent, atf_amc::FPerfSortString &rhs) {
8023 orig_RemoveAll(parent);
8024 int nnew = rhs.orig_n;
8025 orig_Reserve(parent, nnew); // reserve space
8026 for (int i = 0; i < nnew; i++) { // copy elements over
8027 new (parent.orig_elems + i) atf_amc::Cstr(orig_qFind(rhs, i));
8028 parent.orig_n = i + 1;
8029 }
8030}
8031
8032// --- atf_amc.FPerfSortString.orig.Setary2
8033// Copy specified array into orig, discarding previous contents.
8034// If the RHS argument aliases the array (refers to the same memory), throw exception.
8035void atf_amc::orig_Setary(atf_amc::FPerfSortString& parent, const algo::aryptr<atf_amc::Cstr> &rhs) {
8036 orig_RemoveAll(parent);
8037 orig_Addary(parent, rhs);
8038}
8039
8040// --- atf_amc.FPerfSortString.orig.AllocNVal
8041// Reserve space. Insert N elements at the end of the array, return pointer to array
8042algo::aryptr<atf_amc::Cstr> atf_amc::orig_AllocNVal(atf_amc::FPerfSortString& parent, int n_elems, const atf_amc::Cstr& val) {
8043 orig_Reserve(parent, n_elems);
8044 int old_n = parent.orig_n;
8045 int new_n = old_n + n_elems;
8046 atf_amc::Cstr *elems = parent.orig_elems;
8047 for (int i = old_n; i < new_n; i++) {
8048 new (elems + i) atf_amc::Cstr(val);
8049 }
8050 parent.orig_n = new_n;
8051 return algo::aryptr<atf_amc::Cstr>(elems + old_n, n_elems);
8052}
8053
8054// --- atf_amc.FPerfSortString.sorted1.Addary
8055// Reserve space (this may move memory). Insert N element at the end.
8056// Return aryptr to newly inserted block.
8057// If the RHS argument aliases the array (refers to the same memory), exit program with fatal error.
8058algo::aryptr<atf_amc::Cstr> atf_amc::sorted1_Addary(atf_amc::FPerfSortString& parent, algo::aryptr<atf_amc::Cstr> rhs) {
8059 bool overlaps = rhs.n_elems>0 && rhs.elems >= parent.sorted1_elems && rhs.elems < parent.sorted1_elems + parent.sorted1_max;
8060 if (UNLIKELY(overlaps)) {
8061 FatalErrorExit("atf_amc.tary_alias field:atf_amc.FPerfSortString.sorted1 comment:'alias error: sub-array is being appended to the whole'");
8062 }
8063 int nnew = rhs.n_elems;
8064 sorted1_Reserve(parent, nnew); // reserve space
8065 int at = parent.sorted1_n;
8066 for (int i = 0; i < nnew; i++) {
8067 new (parent.sorted1_elems + at + i) atf_amc::Cstr(rhs[i]);
8068 parent.sorted1_n++;
8069 }
8070 return algo::aryptr<atf_amc::Cstr>(parent.sorted1_elems + at, nnew);
8071}
8072
8073// --- atf_amc.FPerfSortString.sorted1.Alloc
8074// Reserve space. Insert element at the end
8075// The new element is initialized to a default value
8076atf_amc::Cstr& atf_amc::sorted1_Alloc(atf_amc::FPerfSortString& parent) {
8077 sorted1_Reserve(parent, 1);
8078 int n = parent.sorted1_n;
8079 int at = n;
8080 atf_amc::Cstr *elems = parent.sorted1_elems;
8081 new (elems + at) atf_amc::Cstr(); // construct new element, default initializer
8082 parent.sorted1_n = n+1;
8083 return elems[at];
8084}
8085
8086// --- atf_amc.FPerfSortString.sorted1.AllocAt
8087// Reserve space for new element, reallocating the array if necessary
8088// Insert new element at specified index. Index must be in range or a fatal error occurs.
8089atf_amc::Cstr& atf_amc::sorted1_AllocAt(atf_amc::FPerfSortString& parent, int at) {
8090 sorted1_Reserve(parent, 1);
8091 int n = parent.sorted1_n;
8092 if (UNLIKELY(u64(at) >= u64(n+1))) {
8093 FatalErrorExit("atf_amc.bad_alloc_at field:atf_amc.FPerfSortString.sorted1 comment:'index out of range'");
8094 }
8095 atf_amc::Cstr *elems = parent.sorted1_elems;
8096 memmove(elems + at + 1, elems + at, (n - at) * sizeof(atf_amc::Cstr));
8097 new (elems + at) atf_amc::Cstr(); // construct element, default initializer
8098 parent.sorted1_n = n+1;
8099 return elems[at];
8100}
8101
8102// --- atf_amc.FPerfSortString.sorted1.AllocN
8103// Reserve space. Insert N elements at the end of the array, return pointer to array
8104algo::aryptr<atf_amc::Cstr> atf_amc::sorted1_AllocN(atf_amc::FPerfSortString& parent, int n_elems) {
8105 sorted1_Reserve(parent, n_elems);
8106 int old_n = parent.sorted1_n;
8107 int new_n = old_n + n_elems;
8108 atf_amc::Cstr *elems = parent.sorted1_elems;
8109 for (int i = old_n; i < new_n; i++) {
8110 new (elems + i) atf_amc::Cstr(); // construct new element, default initialize
8111 }
8112 parent.sorted1_n = new_n;
8113 return algo::aryptr<atf_amc::Cstr>(elems + old_n, n_elems);
8114}
8115
8116// --- atf_amc.FPerfSortString.sorted1.Remove
8117// Remove item by index. If index outside of range, do nothing.
8118void atf_amc::sorted1_Remove(atf_amc::FPerfSortString& parent, u32 i) {
8119 u32 lim = parent.sorted1_n;
8120 atf_amc::Cstr *elems = parent.sorted1_elems;
8121 if (i < lim) {
8122 elems[i].~Cstr(); // destroy element
8123 memmove(elems + i, elems + (i + 1), sizeof(atf_amc::Cstr) * (lim - (i + 1)));
8124 parent.sorted1_n = lim - 1;
8125 }
8126}
8127
8128// --- atf_amc.FPerfSortString.sorted1.RemoveAll
8129void atf_amc::sorted1_RemoveAll(atf_amc::FPerfSortString& parent) {
8130 u32 n = parent.sorted1_n;
8131 while (n > 0) {
8132 n -= 1;
8133 parent.sorted1_elems[n].~Cstr();
8134 parent.sorted1_n = n;
8135 }
8136}
8137
8138// --- atf_amc.FPerfSortString.sorted1.RemoveLast
8139// Delete last element of array. Do nothing if array is empty.
8140void atf_amc::sorted1_RemoveLast(atf_amc::FPerfSortString& parent) {
8141 u64 n = parent.sorted1_n;
8142 if (n > 0) {
8143 n -= 1;
8144 sorted1_qFind(parent, u64(n)).~Cstr();
8145 parent.sorted1_n = n;
8146 }
8147}
8148
8149// --- atf_amc.FPerfSortString.sorted1.AbsReserve
8150// Make sure N elements fit in array. Process dies if out of memory
8151void atf_amc::sorted1_AbsReserve(atf_amc::FPerfSortString& parent, int n) {
8152 u32 old_max = parent.sorted1_max;
8153 if (n > i32(old_max)) {
8154 u32 new_max = i32_Max(i32_Max(old_max * 2, n), 4);
8155 void *new_mem = algo_lib::malloc_ReallocMem(parent.sorted1_elems, old_max * sizeof(atf_amc::Cstr), new_max * sizeof(atf_amc::Cstr));
8156 if (UNLIKELY(!new_mem)) {
8157 FatalErrorExit("atf_amc.tary_nomem field:atf_amc.FPerfSortString.sorted1 comment:'out of memory'");
8158 }
8159 parent.sorted1_elems = (atf_amc::Cstr*)new_mem;
8160 parent.sorted1_max = new_max;
8161 }
8162}
8163
8164// --- atf_amc.FPerfSortString.sorted1.Setary
8165// Copy contents of RHS to PARENT.
8166void atf_amc::sorted1_Setary(atf_amc::FPerfSortString& parent, atf_amc::FPerfSortString &rhs) {
8167 sorted1_RemoveAll(parent);
8168 int nnew = rhs.sorted1_n;
8169 sorted1_Reserve(parent, nnew); // reserve space
8170 for (int i = 0; i < nnew; i++) { // copy elements over
8171 new (parent.sorted1_elems + i) atf_amc::Cstr(sorted1_qFind(rhs, i));
8172 parent.sorted1_n = i + 1;
8173 }
8174}
8175
8176// --- atf_amc.FPerfSortString.sorted1.Setary2
8177// Copy specified array into sorted1, discarding previous contents.
8178// If the RHS argument aliases the array (refers to the same memory), throw exception.
8179void atf_amc::sorted1_Setary(atf_amc::FPerfSortString& parent, const algo::aryptr<atf_amc::Cstr> &rhs) {
8180 sorted1_RemoveAll(parent);
8181 sorted1_Addary(parent, rhs);
8182}
8183
8184// --- atf_amc.FPerfSortString.sorted1.AllocNVal
8185// Reserve space. Insert N elements at the end of the array, return pointer to array
8186algo::aryptr<atf_amc::Cstr> atf_amc::sorted1_AllocNVal(atf_amc::FPerfSortString& parent, int n_elems, const atf_amc::Cstr& val) {
8187 sorted1_Reserve(parent, n_elems);
8188 int old_n = parent.sorted1_n;
8189 int new_n = old_n + n_elems;
8190 atf_amc::Cstr *elems = parent.sorted1_elems;
8191 for (int i = old_n; i < new_n; i++) {
8192 new (elems + i) atf_amc::Cstr(val);
8193 }
8194 parent.sorted1_n = new_n;
8195 return algo::aryptr<atf_amc::Cstr>(elems + old_n, n_elems);
8196}
8197
8198// --- atf_amc.FPerfSortString.sorted1.Swap
8199// Swap values elem_a and elem_b
8200inline static void atf_amc::sorted1_Swap(atf_amc::Cstr &elem_a, atf_amc::Cstr &elem_b) {
8201 u8 temp[sizeof(atf_amc::Cstr)];
8202 memcpy(&temp , &elem_a, sizeof(atf_amc::Cstr));
8203 memcpy(&elem_a, &elem_b, sizeof(atf_amc::Cstr));
8204 memcpy(&elem_b, &temp , sizeof(atf_amc::Cstr));
8205}
8206
8207// --- atf_amc.FPerfSortString.sorted1.Rotleft
8208// Left circular shift of three-tuple
8209inline static void atf_amc::sorted1_Rotleft(atf_amc::Cstr &elem_a, atf_amc::Cstr &elem_b, atf_amc::Cstr &elem_c) {
8210 u8 temp[sizeof(atf_amc::Cstr)];
8211 memcpy(&temp, &elem_a , sizeof(atf_amc::Cstr));
8212 memcpy(&elem_a , &elem_b , sizeof(atf_amc::Cstr));
8213 memcpy(&elem_b , &elem_c , sizeof(atf_amc::Cstr));
8214 memcpy(&elem_c , &temp, sizeof(atf_amc::Cstr));
8215}
8216
8217// --- atf_amc.FPerfSortString.sorted1.Lt
8218// Compare values elem_a and elem_b
8219// The comparison function must be anti-symmetric: if a>b, then !(b>a).
8220// If not, mayhem results.
8221static bool atf_amc::sorted1_Lt(atf_amc::Cstr &elem_a, atf_amc::Cstr &elem_b) {
8222 bool ret;
8223 ret = val_Lt(elem_a, elem_b);
8224 return ret;
8225}
8226
8227// --- atf_amc.FPerfSortString.sorted1.SortedQ
8228// Verify whether array is sorted
8229bool atf_amc::sorted1_SortedQ(atf_amc::FPerfSortString& parent) {
8230 atf_amc::Cstr *elems = sorted1_Getary(parent).elems;
8231 int n = sorted1_N(parent);
8232 for (int i = 1; i < n; i++) {
8233 if (sorted1_Lt(elems[i], elems[i-1])) {
8234 return false;
8235 }
8236 }
8237 return true;
8238}
8239
8240// --- atf_amc.FPerfSortString.sorted1.IntInsertionSort
8241// Internal insertion sort
8242static void atf_amc::sorted1_IntInsertionSort(atf_amc::Cstr *elems, int n) {
8243 for (int i = 1; i < n; ++i) {
8244 int j = i;
8245 // find the spot for ith element.
8246 while (j>0 && sorted1_Lt(elems[i], elems[j-1])) {
8247 j--;
8248 }
8249 if (j<i) {
8250 u8 tmp[sizeof(atf_amc::Cstr)];
8251 memcpy (tmp , &elems[i], sizeof(atf_amc::Cstr) );
8252 memmove(&elems[j+1], &elems[j], sizeof(atf_amc::Cstr)*(i-j));
8253 memcpy (&elems[j] , tmp , sizeof(atf_amc::Cstr) );
8254 }
8255 }
8256}
8257
8258// --- atf_amc.FPerfSortString.sorted1.IntHeapSort
8259// Internal heap sort
8260static void atf_amc::sorted1_IntHeapSort(atf_amc::Cstr *elems, int n) {
8261 // construct max-heap.
8262 // k=current element
8263 // j=parent element
8264 for (int i = 1; i < n; i++) {
8265 int k=i;
8266 int j=(i-1)/2;
8267 while (sorted1_Lt(elems[j], elems[k])) {
8268 sorted1_Swap(elems[k],elems[j]);
8269 k=j;
8270 j=(k-1)/2;
8271 }
8272 }
8273 // remove elements from heap one-by-one,
8274 // deposit them in reverse order starting at the end of ARY.
8275 for (int i = n - 1; i>=0; i--) {
8276 int k = 0;
8277 int l = 1;
8278 while (l<i) {
8279 l += l<i-1 && sorted1_Lt(elems[l], elems[l+1]);
8280 if (sorted1_Lt(elems[l], elems[i])) {
8281 break;
8282 }
8283 sorted1_Swap(elems[k], elems[l]);
8284 k = l;
8285 l = k*2+1;
8286 }
8287 if (i != k) {
8288 sorted1_Swap(elems[i],elems[k]);
8289 }
8290 }
8291}
8292
8293// --- atf_amc.FPerfSortString.sorted1.IntQuickSort
8294// Quick sort engine
8295static void atf_amc::sorted1_IntQuickSort(atf_amc::Cstr *elems, int n, int depth) {
8296 while (n>16) {
8297 // detect degenerate case and revert to heap sort
8298 if (depth==0) {
8299 sorted1_IntHeapSort(elems,n);
8300 return;
8301 }
8302 // elements to sort initially to determine pivot.
8303 // choose pp=n/2 in case the input is already sorted.
8304 int pi = 0;
8305 int pp = n/2;
8306 int pj = n-1;
8307 // insertion sort for 1st, middle and last element
8308 if (sorted1_Lt(elems[pp], elems[pi])) {
8309 sorted1_Swap(elems[pi], elems[pp]);
8310 }
8311 if (sorted1_Lt(elems[pj], elems[pp])) {
8312 if (sorted1_Lt(elems[pj], elems[pi])) {
8313 sorted1_Rotleft(elems[pi], elems[pj], elems[pp]);
8314 } else {
8315 sorted1_Swap(elems[pj], elems[pp]);
8316 }
8317 }
8318 // deposit pivot near the end of the array and skip it.
8319 sorted1_Swap(elems[--pj], elems[pp]);
8320 // reference to pivot
8321 atf_amc::Cstr &pivot = elems[pj];
8322 for(;;){
8323 while (sorted1_Lt(elems[++pi], pivot)) {
8324 }
8325 while (sorted1_Lt(pivot, elems[--pj])) {
8326 }
8327 if (pj <= pi) {
8328 break;
8329 }
8330 sorted1_Swap(elems[pi],elems[pj]);
8331 }
8332 depth -= 1;
8333 sorted1_IntQuickSort(elems, pi, depth);
8334 elems += pi;
8335 n -= pi;
8336 }
8337 // sort the remainder of this section
8338 sorted1_IntInsertionSort(elems,n);
8339}
8340
8341// --- atf_amc.FPerfSortString.sorted1.InsertionSort
8342// Insertion sort
8343void atf_amc::sorted1_InsertionSort(atf_amc::FPerfSortString& parent) {
8344 atf_amc::Cstr *elems = sorted1_Getary(parent).elems;
8345 int n = sorted1_N(parent);
8346 sorted1_IntInsertionSort(elems, n);
8347}
8348
8349// --- atf_amc.FPerfSortString.sorted1.HeapSort
8350// Heap sort
8351void atf_amc::sorted1_HeapSort(atf_amc::FPerfSortString& parent) {
8352 atf_amc::Cstr *elems = sorted1_Getary(parent).elems;
8353 int n = sorted1_N(parent);
8354 sorted1_IntHeapSort(elems, n);
8355}
8356
8357// --- atf_amc.FPerfSortString.sorted1.QuickSort
8358// Quick sort
8359void atf_amc::sorted1_QuickSort(atf_amc::FPerfSortString& parent) {
8360 // compute max recursion depth based on number of elements in the array
8361 int max_depth = algo::CeilingLog2(u32(sorted1_N(parent) + 1)) + 3;
8362 atf_amc::Cstr *elems = sorted1_Getary(parent).elems;
8363 int n = sorted1_N(parent);
8364 sorted1_IntQuickSort(elems, n, max_depth);
8365}
8366
8367// --- atf_amc.FPerfSortString..Uninit
8368void atf_amc::FPerfSortString_Uninit(atf_amc::FPerfSortString& parent) {
8369 atf_amc::FPerfSortString &row = parent; (void)row;
8370
8371 // atf_amc.FPerfSortString.sorted1.Uninit (Tary) //
8372 // remove all elements from atf_amc.FPerfSortString.sorted1
8373 sorted1_RemoveAll(parent);
8374 // free memory for Tary atf_amc.FPerfSortString.sorted1
8375 algo_lib::malloc_FreeMem(parent.sorted1_elems, sizeof(atf_amc::Cstr)*parent.sorted1_max); // (atf_amc.FPerfSortString.sorted1)
8376
8377 // atf_amc.FPerfSortString.orig.Uninit (Tary) //
8378 // remove all elements from atf_amc.FPerfSortString.orig
8379 orig_RemoveAll(parent);
8380 // free memory for Tary atf_amc.FPerfSortString.orig
8381 algo_lib::malloc_FreeMem(parent.orig_elems, sizeof(atf_amc::Cstr)*parent.orig_max); // (atf_amc.FPerfSortString.orig)
8382}
8383
8384// --- atf_amc.FThashElem..Uninit
8385void atf_amc::FThashElem_Uninit(atf_amc::FThashElem& thash_elem) {
8386 atf_amc::FThashElem &row = thash_elem; (void)row;
8387 ind_thash_elem_Remove(row); // remove thash_elem from index ind_thash_elem
8388}
8389
8390// --- atf_amc.FTypeC.msghdr.CopyOut
8391// Copy fields out of row
8392void atf_amc::typec_CopyOut(atf_amc::FTypeC &row, atf_amc::TypeC &out) {
8393 out.typec = row.typec;
8394}
8395
8396// --- atf_amc.FTypeC.msghdr.CopyIn
8397// Copy fields in to row
8398void atf_amc::typec_CopyIn(atf_amc::FTypeC &row, atf_amc::TypeC &in) {
8399 row.typec = in.typec;
8400}
8401
8402// --- atf_amc.FTypeC..Uninit
8403void atf_amc::FTypeC_Uninit(atf_amc::FTypeC& typec) {
8404 atf_amc::FTypeC &row = typec; (void)row;
8405 zsl_h_typec_Remove(row); // remove typec from index zsl_h_typec
8406 zs_t_typec_Remove(row); // remove typec from index zs_t_typec
8407 zs_mt_typec_Remove(row); // remove typec from index zs_mt_typec
8408 bh_typec_Remove(row); // remove typec from index bh_typec
8409 zdl_h_typec_Remove(row); // remove typec from index zdl_h_typec
8410 zd_t_typec_Remove(row); // remove typec from index zd_t_typec
8411 zdl_hnt_typec_Remove(row); // remove typec from index zdl_hnt_typec
8412 csl_h_typec_Remove(row); // remove typec from index csl_h_typec
8413 cs_t_typec_Remove(row); // remove typec from index cs_t_typec
8414 cdl_h_typec_Remove(row); // remove typec from index cdl_h_typec
8415 cd_t_typec_Remove(row); // remove typec from index cd_t_typec
8416}
8417
8418// --- atf_amc.FTypeC..Print
8419// print string representation of ROW to string STR
8420// cfmt:atf_amc.FTypeC.String printfmt:Raw
8421void atf_amc::FTypeC_Print(atf_amc::FTypeC& row, algo::cstring& str) {
8422 i32_Print(row.typec, str);
8423}
8424
8425// --- atf_amc.FTypeA.msghdr.CopyOut
8426// Copy fields out of row
8427void atf_amc::typea_CopyOut(atf_amc::FTypeA &row, atf_amc::TypeA &out) {
8428 out.typea = row.typea;
8429}
8430
8431// --- atf_amc.FTypeA.msghdr.CopyIn
8432// Copy fields in to row
8433void atf_amc::typea_CopyIn(atf_amc::FTypeA &row, atf_amc::TypeA &in) {
8434 row.typea = in.typea;
8435}
8436
8437// --- atf_amc.FTypeA.typec.Alloc
8438// Allocate memory for new default row.
8439// If out of memory, process is killed.
8440atf_amc::FTypeC& atf_amc::typec_Alloc(atf_amc::FTypeA& typea) {
8441 atf_amc::FTypeC* row = typec_AllocMaybe(typea);
8442 if (UNLIKELY(row == NULL)) {
8443 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.FTypeA.typec comment:'Alloc failed'");
8444 }
8445 return *row;
8446}
8447
8448// --- atf_amc.FTypeA.typec.AllocMaybe
8449// Allocate memory for new element. If out of memory, return NULL.
8450atf_amc::FTypeC* atf_amc::typec_AllocMaybe(atf_amc::FTypeA& typea) {
8451 atf_amc::FTypeC *row = (atf_amc::FTypeC*)typec_AllocMem(typea);
8452 if (row) {
8453 new (row) atf_amc::FTypeC; // call constructor
8454 }
8455 return row;
8456}
8457
8458// --- atf_amc.FTypeA.typec.InsertMaybe
8459// Create new row from struct.
8460// Return pointer to new element, or NULL if insertion failed (due to out-of-memory, duplicate key, etc)
8461atf_amc::FTypeC* atf_amc::typec_InsertMaybe(atf_amc::FTypeA& typea, const atf_amc::TypeC &value) {
8462 atf_amc::FTypeC *row = &typec_Alloc(typea); // if out of memory, process dies. if input error, return NULL.
8463 typec_CopyIn(*row,const_cast<atf_amc::TypeC&>(value));
8464 bool ok = typec_XrefMaybe(*row); // this may return false
8465 if (!ok) {
8466 typec_RemoveLast(typea); // delete offending row, any existing xrefs are cleared
8467 row = NULL; // forget this ever happened
8468 }
8469 return row;
8470}
8471
8472// --- atf_amc.FTypeA.typec.RemoveAll
8473// Destroy all elements of Inlary
8474void atf_amc::typec_RemoveAll(atf_amc::FTypeA& typea) {
8475 for (u64 n = typea.typec_n; n>0; ) {
8476 n--;
8477 reinterpret_cast<atf_amc::FTypeC*>(typea.typec_data)[n].~FTypeC(); // destroy last element
8478 typea.typec_n=n;
8479 }
8480}
8481
8482// --- atf_amc.FTypeA.typec.RemoveLast
8483// Delete last element of array. Do nothing if array is empty.
8484void atf_amc::typec_RemoveLast(atf_amc::FTypeA& typea) {
8485 u64 n = typea.typec_n;
8486 if (n > 0) {
8487 n -= 1;
8488 reinterpret_cast<atf_amc::FTypeC*>(typea.typec_data)[n].~FTypeC();
8489 typea.typec_n = n;
8490 }
8491}
8492
8493// --- atf_amc.FTypeA.typec.XrefMaybe
8494// Insert row into all appropriate indices. If error occurs, store error
8495// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
8496bool atf_amc::typec_XrefMaybe(atf_amc::FTypeC &row) {
8497 bool retval = true;
8498 (void)row;
8499 return retval;
8500}
8501
8502// --- atf_amc.FTypeA.zdl_typeb.Cascdel
8503// Delete all elements in the linked list.
8504void atf_amc::zdl_typeb_Cascdel(atf_amc::FTypeA& typea) {
8505 while (atf_amc::FTypeB *zdl_typeb_first = zdl_typeb_First(typea)) {
8506 typeb_Delete(*zdl_typeb_first);
8507 }
8508}
8509
8510// --- atf_amc.FTypeA.zdl_typeb.Insert
8511// Insert row into linked list. If row is already in linked list, do nothing.
8512void atf_amc::zdl_typeb_Insert(atf_amc::FTypeA& typea, atf_amc::FTypeB& row) {
8513 if (!zdl_typeb_InLlistQ(row)) {
8514 atf_amc::FTypeB* old_head = typea.zdl_typeb_head;
8515 row.zdl_typeb_prev = NULL;
8516 row.zdl_typeb_next = old_head;
8517 typea.zdl_typeb_head = &row;
8518 atf_amc::FTypeB **new_row_a = &old_head->zdl_typeb_prev;
8519 atf_amc::FTypeB **new_row_b = &typea.zdl_typeb_tail;
8520 atf_amc::FTypeB **new_row = old_head ? new_row_a : new_row_b;
8521 *new_row = &row;
8522 typea.zdl_typeb_n++;
8523 }
8524}
8525
8526// --- atf_amc.FTypeA.zdl_typeb.Remove
8527// Remove element from index. If element is not in index, do nothing.
8528void atf_amc::zdl_typeb_Remove(atf_amc::FTypeA& typea, atf_amc::FTypeB& row) {
8529 if (zdl_typeb_InLlistQ(row)) {
8530 atf_amc::FTypeB* old_head = typea.zdl_typeb_head;
8531 (void)old_head; // in case it's not used
8532 atf_amc::FTypeB* prev = row.zdl_typeb_prev;
8533 atf_amc::FTypeB* next = row.zdl_typeb_next;
8534 // if element is first, adjust list head; otherwise, adjust previous element's next
8535 atf_amc::FTypeB **new_next_a = &prev->zdl_typeb_next;
8536 atf_amc::FTypeB **new_next_b = &typea.zdl_typeb_head;
8537 atf_amc::FTypeB **new_next = prev ? new_next_a : new_next_b;
8538 *new_next = next;
8539 // if element is last, adjust list tail; otherwise, adjust next element's prev
8540 atf_amc::FTypeB **new_prev_a = &next->zdl_typeb_prev;
8541 atf_amc::FTypeB **new_prev_b = &typea.zdl_typeb_tail;
8542 atf_amc::FTypeB **new_prev = next ? new_prev_a : new_prev_b;
8543 *new_prev = prev;
8544 typea.zdl_typeb_n--;
8545 row.zdl_typeb_next=(atf_amc::FTypeB*)-1; // not-in-list
8546 }
8547}
8548
8549// --- atf_amc.FTypeA.zdl_typeb.RemoveAll
8550// Empty the index. (The rows are not deleted)
8551void atf_amc::zdl_typeb_RemoveAll(atf_amc::FTypeA& typea) {
8552 atf_amc::FTypeB* row = typea.zdl_typeb_head;
8553 typea.zdl_typeb_head = NULL;
8554 typea.zdl_typeb_tail = NULL;
8555 typea.zdl_typeb_n = 0;
8556 while (row) {
8557 atf_amc::FTypeB* row_next = row->zdl_typeb_next;
8558 row->zdl_typeb_next = (atf_amc::FTypeB*)-1;
8559 row->zdl_typeb_prev = NULL;
8560 row = row_next;
8561 }
8562}
8563
8564// --- atf_amc.FTypeA.zdl_typeb.RemoveFirst
8565// If linked list is empty, return NULL. Otherwise unlink and return pointer to first element.
8566atf_amc::FTypeB* atf_amc::zdl_typeb_RemoveFirst(atf_amc::FTypeA& typea) {
8567 atf_amc::FTypeB *row = NULL;
8568 row = typea.zdl_typeb_head;
8569 if (row) {
8570 atf_amc::FTypeB *next = row->zdl_typeb_next;
8571 typea.zdl_typeb_head = next;
8572 atf_amc::FTypeB **new_end_a = &next->zdl_typeb_prev;
8573 atf_amc::FTypeB **new_end_b = &typea.zdl_typeb_tail;
8574 atf_amc::FTypeB **new_end = next ? new_end_a : new_end_b;
8575 *new_end = NULL;
8576 typea.zdl_typeb_n--;
8577 row->zdl_typeb_next = (atf_amc::FTypeB*)-1; // mark as not-in-list
8578 }
8579 return row;
8580}
8581
8582// --- atf_amc.FTypeA.bh_typeb.Cascdel
8583// Delete referred-to items.
8584// Delete all elements referenced by the heap.
8585void atf_amc::bh_typeb_Cascdel(atf_amc::FTypeA& typea) {
8586 i32 n = typea.bh_typeb_n;
8587 while (n > 0) {
8588 n--;
8589 atf_amc::FTypeB &elem = *typea.bh_typeb_elems[n]; // pick cheapest element to remove
8590 elem.bh_typeb_idx = -1; // mark not-in-heap
8591 typea.bh_typeb_n = n;
8592 typeb_Delete(elem);
8593 }
8594}
8595
8596// --- atf_amc.FTypeA.bh_typeb.Dealloc
8597// Remove all elements from heap and free memory used by the array.
8598void atf_amc::bh_typeb_Dealloc(atf_amc::FTypeA& typea) {
8599 bh_typeb_RemoveAll(typea);
8600 algo_lib::malloc_FreeMem(typea.bh_typeb_elems, sizeof(atf_amc::FTypeB*)*typea.bh_typeb_max);
8601 typea.bh_typeb_max = 0;
8602 typea.bh_typeb_elems = NULL;
8603}
8604
8605// --- atf_amc.FTypeA.bh_typeb.Downheap
8606// Find new location for ROW starting at IDX
8607// NOTE: Rest of heap is rearranged, but pointer to ROW is NOT stored in array.
8608static int atf_amc::bh_typeb_Downheap(atf_amc::FTypeA& typea, atf_amc::FTypeB& row, int idx) {
8609 atf_amc::FTypeB* *elems = typea.bh_typeb_elems;
8610 int n = typea.bh_typeb_n;
8611 int child = idx*2+1;
8612 while (child < n) {
8613 atf_amc::FTypeB* p = elems[child]; // left child
8614 int rchild = child+1;
8615 if (rchild < n) {
8616 atf_amc::FTypeB* q = elems[rchild]; // right child
8617 if (bh_typeb_ElemLt(typea, *q,*p)) {
8618 child = rchild;
8619 p = q;
8620 }
8621 }
8622 if (!bh_typeb_ElemLt(typea, *p,row)) {
8623 break;
8624 }
8625 p->bh_typeb_idx = idx;
8626 elems[idx] = p;
8627 idx = child;
8628 child = idx*2+1;
8629 }
8630 return idx;
8631}
8632
8633// --- atf_amc.FTypeA.bh_typeb.Insert
8634// Insert row. Row must not already be in index. If row is already in index, do nothing.
8635void atf_amc::bh_typeb_Insert(atf_amc::FTypeA& typea, atf_amc::FTypeB& row) {
8636 if (LIKELY(row.bh_typeb_idx == -1)) {
8637 bh_typeb_Reserve(typea, 1);
8638 int n = typea.bh_typeb_n;
8639 typea.bh_typeb_n = n + 1;
8640 int new_idx = bh_typeb_Upheap(typea, row, n);
8641 row.bh_typeb_idx = new_idx;
8642 typea.bh_typeb_elems[new_idx] = &row;
8643 }
8644}
8645
8646// --- atf_amc.FTypeA.bh_typeb.Reheap
8647// If row is in heap, update its position. If row is not in heap, insert it.
8648// Return new position of item in the heap (0=top)
8649i32 atf_amc::bh_typeb_Reheap(atf_amc::FTypeA& typea, atf_amc::FTypeB& row) {
8650 int old_idx = row.bh_typeb_idx;
8651 bool isnew = old_idx == -1;
8652 if (isnew) {
8653 bh_typeb_Reserve(typea, 1);
8654 old_idx = typea.bh_typeb_n++;
8655 }
8656 int new_idx = bh_typeb_Upheap(typea, row, old_idx);
8657 if (!isnew && new_idx == old_idx) {
8658 new_idx = bh_typeb_Downheap(typea, row, old_idx);
8659 }
8660 row.bh_typeb_idx = new_idx;
8661 typea.bh_typeb_elems[new_idx] = &row;
8662 return new_idx;
8663}
8664
8665// --- atf_amc.FTypeA.bh_typeb.ReheapFirst
8666// Key of first element in the heap changed. Move it.
8667// This function does not check the insert condition.
8668// Return new position of item in the heap (0=top).
8669// Heap must be non-empty or behavior is undefined.
8670i32 atf_amc::bh_typeb_ReheapFirst(atf_amc::FTypeA& typea) {
8671 atf_amc::FTypeB &row = *typea.bh_typeb_elems[0];
8672 i32 new_idx = bh_typeb_Downheap(typea, row, 0);
8673 row.bh_typeb_idx = new_idx;
8674 typea.bh_typeb_elems[new_idx] = &row;
8675 return new_idx;
8676}
8677
8678// --- atf_amc.FTypeA.bh_typeb.Remove
8679// Remove element from index. If element is not in index, do nothing.
8680void atf_amc::bh_typeb_Remove(atf_amc::FTypeA& typea, atf_amc::FTypeB& row) {
8681 if (bh_typeb_InBheapQ(row)) {
8682 int old_idx = row.bh_typeb_idx;
8683 if (typea.bh_typeb_elems[old_idx] == &row) { // sanity check: heap points back to row
8684 row.bh_typeb_idx = -1; // mark not in heap
8685 i32 n = typea.bh_typeb_n - 1; // index of last element in heap
8686 typea.bh_typeb_n = n; // decrease count
8687 if (old_idx != n) {
8688 atf_amc::FTypeB *elem = typea.bh_typeb_elems[n];
8689 int new_idx = bh_typeb_Upheap(typea, *elem, old_idx);
8690 if (new_idx == old_idx) {
8691 new_idx = bh_typeb_Downheap(typea, *elem, old_idx);
8692 }
8693 elem->bh_typeb_idx = new_idx;
8694 typea.bh_typeb_elems[new_idx] = elem;
8695 }
8696 }
8697 }
8698}
8699
8700// --- atf_amc.FTypeA.bh_typeb.RemoveAll
8701// Remove all elements from binary heap
8702void atf_amc::bh_typeb_RemoveAll(atf_amc::FTypeA& typea) {
8703 int n = typea.bh_typeb_n;
8704 for (int i = n - 1; i>=0; i--) {
8705 typea.bh_typeb_elems[i]->bh_typeb_idx = -1; // mark not-in-heap
8706 }
8707 typea.bh_typeb_n = 0;
8708}
8709
8710// --- atf_amc.FTypeA.bh_typeb.RemoveFirst
8711// If index is empty, return NULL. Otherwise remove and return first key in index.
8712// Call 'head changed' trigger.
8713atf_amc::FTypeB* atf_amc::bh_typeb_RemoveFirst(atf_amc::FTypeA& typea) {
8714 atf_amc::FTypeB *row = NULL;
8715 if (typea.bh_typeb_n > 0) {
8716 row = typea.bh_typeb_elems[0];
8717 row->bh_typeb_idx = -1; // mark not in heap
8718 i32 n = typea.bh_typeb_n - 1; // index of last element in heap
8719 typea.bh_typeb_n = n; // decrease count
8720 if (n) {
8721 atf_amc::FTypeB &elem = *typea.bh_typeb_elems[n];
8722 int new_idx = bh_typeb_Downheap(typea, elem, 0);
8723 elem.bh_typeb_idx = new_idx;
8724 typea.bh_typeb_elems[new_idx] = &elem;
8725 }
8726 }
8727 return row;
8728}
8729
8730// --- atf_amc.FTypeA.bh_typeb.Reserve
8731// Reserve space in index for N more elements
8732void atf_amc::bh_typeb_Reserve(atf_amc::FTypeA& typea, int n) {
8733 i32 old_max = typea.bh_typeb_max;
8734 if (UNLIKELY(typea.bh_typeb_n + n > old_max)) {
8735 u32 new_max = u32_Max(4, old_max * 2);
8736 u32 old_size = old_max * sizeof(atf_amc::FTypeB*);
8737 u32 new_size = new_max * sizeof(atf_amc::FTypeB*);
8738 void *new_mem = algo_lib::malloc_ReallocMem(typea.bh_typeb_elems, old_size, new_size);
8739 if (UNLIKELY(!new_mem)) {
8740 FatalErrorExit("atf_amc.out_of_memory field:atf_amc.FTypeA.bh_typeb");
8741 }
8742 typea.bh_typeb_elems = (atf_amc::FTypeB**)new_mem;
8743 typea.bh_typeb_max = new_max;
8744 }
8745}
8746
8747// --- atf_amc.FTypeA.bh_typeb.Upheap
8748// Find and return index of new location for element ROW in the heap, starting at index IDX.
8749// Move any elements along the way but do not modify ROW.
8750static int atf_amc::bh_typeb_Upheap(atf_amc::FTypeA& typea, atf_amc::FTypeB& row, int idx) {
8751 atf_amc::FTypeB* *elems = typea.bh_typeb_elems;
8752 while (idx>0) {
8753 int j = (idx-1)/2;
8754 atf_amc::FTypeB* p = elems[j];
8755 if (!bh_typeb_ElemLt(typea, row, *p)) {
8756 break;
8757 }
8758 p->bh_typeb_idx = idx;
8759 elems[idx] = p;
8760 idx = j;
8761 }
8762 return idx;
8763}
8764
8765// --- atf_amc.FTypeA.bh_typeb.ElemLt
8766inline static bool atf_amc::bh_typeb_ElemLt(atf_amc::FTypeA& typea, atf_amc::FTypeB &a, atf_amc::FTypeB &b) {
8767 (void)typea;
8768 return a.j < b.j;
8769}
8770
8771// --- atf_amc.FTypeA..Init
8772// Set all fields to initial values.
8773void atf_amc::FTypeA_Init(atf_amc::FTypeA& typea) {
8774 typea.typea = i32(0);
8775 typea.typec_n = 0; // typec: initialize count
8776 typea.zdl_typeb_head = NULL; // (atf_amc.FTypeA.zdl_typeb)
8777 typea.zdl_typeb_n = 0; // (atf_amc.FTypeA.zdl_typeb)
8778 typea.zdl_typeb_tail = NULL; // (atf_amc.FTypeA.zdl_typeb)
8779 typea.rowid = i32(0);
8780 typea.bh_typeb_max = 0; // (atf_amc.FTypeA.bh_typeb)
8781 typea.bh_typeb_n = 0; // (atf_amc.FTypeA.bh_typeb)
8782 typea.bh_typeb_elems = NULL; // (atf_amc.FTypeA.bh_typeb)
8783 typea.ind_typea_next = (atf_amc::FTypeA*)-1; // (atf_amc.FDb.ind_typea) not-in-hash
8784}
8785
8786// --- atf_amc.FTypeA.bh_typeb_curs.Add
8787static void atf_amc::typea_bh_typeb_curs_Add(typea_bh_typeb_curs &curs, atf_amc::FTypeB& row) {
8788 u32 n = curs.temp_n;
8789 int i = n;
8790 curs.temp_n = n+1;
8791 atf_amc::FTypeB* *elems = curs.temp_elems;
8792 while (i>0) {
8793 int j = (i-1)/2;
8794 atf_amc::FTypeB* p = elems[j];
8795 if (!bh_typeb_ElemLt((*curs.parent), row,*p)) {
8796 break;
8797 }
8798 elems[i]=p;
8799 i=j;
8800 }
8801 elems[i]=&row;
8802}
8803
8804// --- atf_amc.FTypeA.bh_typeb_curs.Reserve
8805void atf_amc::typea_bh_typeb_curs_Reserve(typea_bh_typeb_curs &curs, int n) {
8806 if (n > curs.temp_max) {
8807 size_t old_size = sizeof(void*) * curs.temp_max;
8808 size_t new_size = sizeof(void*) * bh_typeb_N((*curs.parent));
8809 curs.temp_elems = (atf_amc::FTypeB**)algo_lib::malloc_ReallocMem(curs.temp_elems, old_size, new_size);
8810 if (!curs.temp_elems) {
8811 algo::FatalErrorExit("atf_amc.cursor_out_of_memory func:atf_amc.FTypeA.bh_typeb_curs.Reserve");
8812 }
8813 curs.temp_max = bh_typeb_N((*curs.parent));
8814 }
8815}
8816
8817// --- atf_amc.FTypeA.bh_typeb_curs.Reset
8818// Reset cursor. If HEAP is non-empty, add its top element to CURS.
8819void atf_amc::typea_bh_typeb_curs_Reset(typea_bh_typeb_curs &curs, atf_amc::FTypeA &parent) {
8820 curs.parent = &parent;
8821 typea_bh_typeb_curs_Reserve(curs, bh_typeb_N((*curs.parent)));
8822 curs.temp_n = 0;
8823 if (parent.bh_typeb_n > 0) {
8824 atf_amc::FTypeB &first = *parent.bh_typeb_elems[0];
8825 curs.temp_elems[0] = &first; // insert first element in heap
8826 curs.temp_n = 1;
8827 }
8828}
8829
8830// --- atf_amc.FTypeA.bh_typeb_curs.Next
8831// Advance cursor.
8832void atf_amc::typea_bh_typeb_curs_Next(typea_bh_typeb_curs &curs) {
8833 atf_amc::FTypeB* *elems = curs.temp_elems;
8834 int n = curs.temp_n;
8835 if (n > 0) {
8836 // remove top element from heap
8837 atf_amc::FTypeB* dead = elems[0];
8838 int i = 0;
8839 atf_amc::FTypeB* last = curs.temp_elems[n-1];
8840 // downheap last elem
8841 do {
8842 atf_amc::FTypeB* choose = last;
8843 int l = i*2+1;
8844 if (l<n) {
8845 atf_amc::FTypeB* el = elems[l];
8846 int r = l+1;
8847 r -= r==n;
8848 atf_amc::FTypeB* er = elems[r];
8849 if (bh_typeb_ElemLt((*curs.parent),*er,*el)) {
8850 el = er;
8851 l = r;
8852 }
8853 bool b = bh_typeb_ElemLt((*curs.parent),*el,*last);
8854 if (b) choose = el;
8855 if (!b) l = n;
8856 }
8857 elems[i] = choose;
8858 i = l;
8859 } while (i < n);
8860 curs.temp_n = n-1;
8861 int index = dead->bh_typeb_idx;
8862 i = (index*2+1);
8863 if (i < bh_typeb_N((*curs.parent))) {
8864 atf_amc::FTypeB &elem = *curs.parent->bh_typeb_elems[i];
8865 typea_bh_typeb_curs_Add(curs, elem);
8866 }
8867 if (i+1 < bh_typeb_N((*curs.parent))) {
8868 atf_amc::FTypeB &elem = *curs.parent->bh_typeb_elems[i + 1];
8869 typea_bh_typeb_curs_Add(curs, elem);
8870 }
8871 }
8872}
8873
8874// --- atf_amc.FTypeA..Uninit
8875void atf_amc::FTypeA_Uninit(atf_amc::FTypeA& typea) {
8876 atf_amc::FTypeA &row = typea; (void)row;
8877 bh_typeb_Cascdel(typea); // dmmeta.cascdel:atf_amc.FTypeA.bh_typeb
8878 zdl_typeb_Cascdel(typea); // dmmeta.cascdel:atf_amc.FTypeA.zdl_typeb
8879 ind_typea_Remove(row); // remove typea from index ind_typea
8880
8881 // atf_amc.FTypeA.bh_typeb.Uninit (Bheap) //
8882 algo_lib::malloc_FreeMem((u8*)typea.bh_typeb_elems, sizeof(atf_amc::FTypeB*)*typea.bh_typeb_max); // (atf_amc.FTypeA.bh_typeb)
8883
8884 // atf_amc.FTypeA.typec.Uninit (Inlary) //
8885 typec_RemoveAll(typea);
8886}
8887
8888// --- atf_amc.FTypeA..Print
8889// print string representation of ROW to string STR
8890// cfmt:atf_amc.FTypeA.String printfmt:Tuple
8891void atf_amc::FTypeA_Print(atf_amc::FTypeA& row, algo::cstring& str) {
8892 algo::tempstr temp;
8893 str << "atf_amc.FTypeA";
8894
8895 i32_Print(row.typea, temp);
8896 PrintAttrSpaceReset(str,"typea", temp);
8897
8898 ind_beg(typea_typec_curs,typec,row) {
8899 atf_amc::FTypeC_Print(typec, temp);
8900 tempstr name;
8901 name << "typec.";
8902 name << ind_curs(typec).index;
8903 PrintAttrSpaceReset(str, name, temp);
8904 }ind_end;
8905
8906 i32_Print(row.rowid, temp);
8907 PrintAttrSpaceReset(str,"rowid", temp);
8908}
8909
8910// --- atf_amc.FTypeB.msghdr.CopyOut
8911// Copy fields out of row
8912void atf_amc::typeb_CopyOut(atf_amc::FTypeB &row, atf_amc::TypeB &out) {
8913 out.typea = row.typea;
8914 out.j = row.j;
8915}
8916
8917// --- atf_amc.FTypeB.msghdr.CopyIn
8918// Copy fields in to row
8919void atf_amc::typeb_CopyIn(atf_amc::FTypeB &row, atf_amc::TypeB &in) {
8920 row.typea = in.typea;
8921 row.j = in.j;
8922}
8923
8924// --- atf_amc.FTypeB..Uninit
8925void atf_amc::FTypeB_Uninit(atf_amc::FTypeB& typeb) {
8926 atf_amc::FTypeB &row = typeb; (void)row;
8927 atf_amc::FTypeA* p_typea = atf_amc::ind_typea_Find(row.typea);
8928 if (p_typea) {
8929 zdl_typeb_Remove(*p_typea, row);// remove typeb from index zdl_typeb
8930 }
8931 if (p_typea) {
8932 bh_typeb_Remove(*p_typea, row);// remove typeb from index bh_typeb
8933 }
8934}
8935
8936// --- atf_amc.FTypeB..Print
8937// print string representation of ROW to string STR
8938// cfmt:atf_amc.FTypeB.String printfmt:Tuple
8939void atf_amc::FTypeB_Print(atf_amc::FTypeB& row, algo::cstring& str) {
8940 algo::tempstr temp;
8941 str << "atf_amc.FTypeB";
8942
8943 i32_Print(row.typea, temp);
8944 PrintAttrSpaceReset(str,"typea", temp);
8945
8946 i32_Print(row.j, temp);
8947 PrintAttrSpaceReset(str,"j", temp);
8948}
8949
8950// --- atf_amc.FTypeD.msghdr.CopyOut
8951// Copy fields out of row
8952void atf_amc::typed_CopyOut(atf_amc::FTypeD &row, atf_amc::TypeC &out) {
8953 out.typec = row.typec;
8954}
8955
8956// --- atf_amc.FTypeD.msghdr.CopyIn
8957// Copy fields in to row
8958void atf_amc::typed_CopyIn(atf_amc::FTypeD &row, atf_amc::TypeC &in) {
8959 row.typec = in.typec;
8960}
8961
8962// --- atf_amc.FTypeD..Uninit
8963void atf_amc::FTypeD_Uninit(atf_amc::FTypeD& typed) {
8964 atf_amc::FTypeD &row = typed; (void)row;
8965 zd_typed_Remove(row); // remove typed from index zd_typed
8966 zs_t_typed_Remove(row); // remove typed from index zs_t_typed
8967 cd_typed_Remove(row); // remove typed from index cd_typed
8968}
8969
8970// --- atf_amc.FTypeD..Print
8971// print string representation of ROW to string STR
8972// cfmt:atf_amc.FTypeD.String printfmt:Raw
8973void atf_amc::FTypeD_Print(atf_amc::FTypeD& row, algo::cstring& str) {
8974 i32_Print(row.typec, str);
8975}
8976
8977// --- atf_amc.FTypeS.msghdr.CopyOut
8978// Copy fields out of row
8979void atf_amc::types_CopyOut(atf_amc::FTypeS &row, atf_amc::TypeS &out) {
8980 out.types = row.types;
8981 out.comment = row.comment;
8982}
8983
8984// --- atf_amc.FTypeS.msghdr.CopyIn
8985// Copy fields in to row
8986void atf_amc::types_CopyIn(atf_amc::FTypeS &row, atf_amc::TypeS &in) {
8987 row.types = in.types;
8988 row.comment = in.comment;
8989}
8990
8991// --- atf_amc.FTypeS.zdl_typet.Insert
8992// Insert row into linked list. If row is already in linked list, do nothing.
8993void atf_amc::zdl_typet_Insert(atf_amc::FTypeS& types, atf_amc::FTypeT& row) {
8994 if (!zdl_typet_InLlistQ(row)) {
8995 atf_amc::FTypeT* old_head = types.zdl_typet_head;
8996 row.zdl_typet_prev = NULL;
8997 row.zdl_typet_next = old_head;
8998 types.zdl_typet_head = &row;
8999 atf_amc::FTypeT **new_row_a = &old_head->zdl_typet_prev;
9000 atf_amc::FTypeT **new_row_b = &types.zdl_typet_tail;
9001 atf_amc::FTypeT **new_row = old_head ? new_row_a : new_row_b;
9002 *new_row = &row;
9003 types.zdl_typet_n++;
9004 }
9005}
9006
9007// --- atf_amc.FTypeS.zdl_typet.Remove
9008// Remove element from index. If element is not in index, do nothing.
9009void atf_amc::zdl_typet_Remove(atf_amc::FTypeS& types, atf_amc::FTypeT& row) {
9010 if (zdl_typet_InLlistQ(row)) {
9011 atf_amc::FTypeT* old_head = types.zdl_typet_head;
9012 (void)old_head; // in case it's not used
9013 atf_amc::FTypeT* prev = row.zdl_typet_prev;
9014 atf_amc::FTypeT* next = row.zdl_typet_next;
9015 // if element is first, adjust list head; otherwise, adjust previous element's next
9016 atf_amc::FTypeT **new_next_a = &prev->zdl_typet_next;
9017 atf_amc::FTypeT **new_next_b = &types.zdl_typet_head;
9018 atf_amc::FTypeT **new_next = prev ? new_next_a : new_next_b;
9019 *new_next = next;
9020 // if element is last, adjust list tail; otherwise, adjust next element's prev
9021 atf_amc::FTypeT **new_prev_a = &next->zdl_typet_prev;
9022 atf_amc::FTypeT **new_prev_b = &types.zdl_typet_tail;
9023 atf_amc::FTypeT **new_prev = next ? new_prev_a : new_prev_b;
9024 *new_prev = prev;
9025 types.zdl_typet_n--;
9026 row.zdl_typet_next=(atf_amc::FTypeT*)-1; // not-in-list
9027 }
9028}
9029
9030// --- atf_amc.FTypeS.zdl_typet.RemoveAll
9031// Empty the index. (The rows are not deleted)
9032void atf_amc::zdl_typet_RemoveAll(atf_amc::FTypeS& types) {
9033 atf_amc::FTypeT* row = types.zdl_typet_head;
9034 types.zdl_typet_head = NULL;
9035 types.zdl_typet_tail = NULL;
9036 types.zdl_typet_n = 0;
9037 while (row) {
9038 atf_amc::FTypeT* row_next = row->zdl_typet_next;
9039 row->zdl_typet_next = (atf_amc::FTypeT*)-1;
9040 row->zdl_typet_prev = NULL;
9041 row = row_next;
9042 }
9043}
9044
9045// --- atf_amc.FTypeS.zdl_typet.RemoveFirst
9046// If linked list is empty, return NULL. Otherwise unlink and return pointer to first element.
9047atf_amc::FTypeT* atf_amc::zdl_typet_RemoveFirst(atf_amc::FTypeS& types) {
9048 atf_amc::FTypeT *row = NULL;
9049 row = types.zdl_typet_head;
9050 if (row) {
9051 atf_amc::FTypeT *next = row->zdl_typet_next;
9052 types.zdl_typet_head = next;
9053 atf_amc::FTypeT **new_end_a = &next->zdl_typet_prev;
9054 atf_amc::FTypeT **new_end_b = &types.zdl_typet_tail;
9055 atf_amc::FTypeT **new_end = next ? new_end_a : new_end_b;
9056 *new_end = NULL;
9057 types.zdl_typet_n--;
9058 row->zdl_typet_next = (atf_amc::FTypeT*)-1; // mark as not-in-list
9059 }
9060 return row;
9061}
9062
9063// --- atf_amc.FTypeS..Uninit
9064void atf_amc::FTypeS_Uninit(atf_amc::FTypeS& types) {
9065 atf_amc::FTypeS &row = types; (void)row;
9066 ind_types_Remove(row); // remove types from index ind_types
9067}
9068
9069// --- atf_amc.FTypeS..Print
9070// print string representation of ROW to string STR
9071// cfmt:atf_amc.FTypeS.String printfmt:Tuple
9072void atf_amc::FTypeS_Print(atf_amc::FTypeS& row, algo::cstring& str) {
9073 algo::tempstr temp;
9074 str << "atf_amc.FTypeS";
9075
9076 i32_Print(row.types, temp);
9077 PrintAttrSpaceReset(str,"types", temp);
9078
9079 algo::Comment_Print(row.comment, temp);
9080 PrintAttrSpaceReset(str,"comment", temp);
9081}
9082
9083// --- atf_amc.FTypeT.msghdr.CopyOut
9084// Copy fields out of row
9085void atf_amc::typet_CopyOut(atf_amc::FTypeT &row, atf_amc::TypeT &out) {
9086 out.types = row.types;
9087 out.j = row.j;
9088}
9089
9090// --- atf_amc.FTypeT.msghdr.CopyIn
9091// Copy fields in to row
9092void atf_amc::typet_CopyIn(atf_amc::FTypeT &row, atf_amc::TypeT &in) {
9093 row.types = in.types;
9094 row.j = in.j;
9095}
9096
9097// --- atf_amc.FTypeT..Uninit
9098void atf_amc::FTypeT_Uninit(atf_amc::FTypeT& typet) {
9099 atf_amc::FTypeT &row = typet; (void)row;
9100 atf_amc::FTypeS* p_types = atf_amc::ind_types_Find(row.types);
9101 if (p_types) {
9102 zdl_typet_Remove(*p_types, row);// remove typet from index zdl_typet
9103 }
9104}
9105
9106// --- atf_amc.FTypeT..Print
9107// print string representation of ROW to string STR
9108// cfmt:atf_amc.FTypeT.String printfmt:Tuple
9109void atf_amc::FTypeT_Print(atf_amc::FTypeT& row, algo::cstring& str) {
9110 algo::tempstr temp;
9111 str << "atf_amc.FTypeT";
9112
9113 i32_Print(row.types, temp);
9114 PrintAttrSpaceReset(str,"types", temp);
9115
9116 i32_Print(row.j, temp);
9117 PrintAttrSpaceReset(str,"j", temp);
9118}
9119
9120// --- atf_amc.TypeA..ReadStrptrMaybe
9121// Read fields of atf_amc::TypeA from an ascii string.
9122// The format of the string is the format of the atf_amc::TypeA's only field
9123bool atf_amc::TypeA_ReadStrptrMaybe(atf_amc::TypeA &parent, algo::strptr in_str) {
9124 bool retval = true;
9125 retval = retval && i32_ReadStrptrMaybe(parent.typea, in_str);
9126 return retval;
9127}
9128
9129// --- atf_amc.TypeA..FmtJson
9130// Create JSON representation of atf_amc::TypeA under PARENT node
9131// cfmt:atf_amc.TypeA.Json printfmt:Auto
9132lib_json::FNode * atf_amc::TypeA_FmtJson(atf_amc::TypeA& row, lib_json::FNode *parent) {
9133 return i32_FmtJson(const_cast<atf_amc::TypeA&>(row).typea,parent);;
9134}
9135
9136// --- atf_amc.TypeA..Print
9137// print string representation of ROW to string STR
9138// cfmt:atf_amc.TypeA.String printfmt:Raw
9139void atf_amc::TypeA_Print(atf_amc::TypeA& row, algo::cstring& str) {
9140 i32_Print(row.typea, str);
9141}
9142
9143// --- atf_amc.FUnitSort.tary.Addary
9144// Reserve space (this may move memory). Insert N element at the end.
9145// Return aryptr to newly inserted block.
9146// If the RHS argument aliases the array (refers to the same memory), exit program with fatal error.
9147algo::aryptr<atf_amc::TypeA> atf_amc::tary_Addary(atf_amc::FUnitSort& parent, algo::aryptr<atf_amc::TypeA> rhs) {
9148 bool overlaps = rhs.n_elems>0 && rhs.elems >= parent.tary_elems && rhs.elems < parent.tary_elems + parent.tary_max;
9149 if (UNLIKELY(overlaps)) {
9150 FatalErrorExit("atf_amc.tary_alias field:atf_amc.FUnitSort.tary comment:'alias error: sub-array is being appended to the whole'");
9151 }
9152 int nnew = rhs.n_elems;
9153 tary_Reserve(parent, nnew); // reserve space
9154 int at = parent.tary_n;
9155 for (int i = 0; i < nnew; i++) {
9156 new (parent.tary_elems + at + i) atf_amc::TypeA(rhs[i]);
9157 parent.tary_n++;
9158 }
9159 return algo::aryptr<atf_amc::TypeA>(parent.tary_elems + at, nnew);
9160}
9161
9162// --- atf_amc.FUnitSort.tary.Alloc
9163// Reserve space. Insert element at the end
9164// The new element is initialized to a default value
9165atf_amc::TypeA& atf_amc::tary_Alloc(atf_amc::FUnitSort& parent) {
9166 tary_Reserve(parent, 1);
9167 int n = parent.tary_n;
9168 int at = n;
9169 atf_amc::TypeA *elems = parent.tary_elems;
9170 new (elems + at) atf_amc::TypeA(); // construct new element, default initializer
9171 parent.tary_n = n+1;
9172 return elems[at];
9173}
9174
9175// --- atf_amc.FUnitSort.tary.AllocAt
9176// Reserve space for new element, reallocating the array if necessary
9177// Insert new element at specified index. Index must be in range or a fatal error occurs.
9178atf_amc::TypeA& atf_amc::tary_AllocAt(atf_amc::FUnitSort& parent, int at) {
9179 tary_Reserve(parent, 1);
9180 int n = parent.tary_n;
9181 if (UNLIKELY(u64(at) >= u64(n+1))) {
9182 FatalErrorExit("atf_amc.bad_alloc_at field:atf_amc.FUnitSort.tary comment:'index out of range'");
9183 }
9184 atf_amc::TypeA *elems = parent.tary_elems;
9185 memmove(elems + at + 1, elems + at, (n - at) * sizeof(atf_amc::TypeA));
9186 new (elems + at) atf_amc::TypeA(); // construct element, default initializer
9187 parent.tary_n = n+1;
9188 return elems[at];
9189}
9190
9191// --- atf_amc.FUnitSort.tary.AllocN
9192// Reserve space. Insert N elements at the end of the array, return pointer to array
9193algo::aryptr<atf_amc::TypeA> atf_amc::tary_AllocN(atf_amc::FUnitSort& parent, int n_elems) {
9194 tary_Reserve(parent, n_elems);
9195 int old_n = parent.tary_n;
9196 int new_n = old_n + n_elems;
9197 atf_amc::TypeA *elems = parent.tary_elems;
9198 for (int i = old_n; i < new_n; i++) {
9199 new (elems + i) atf_amc::TypeA(); // construct new element, default initialize
9200 }
9201 parent.tary_n = new_n;
9202 return algo::aryptr<atf_amc::TypeA>(elems + old_n, n_elems);
9203}
9204
9205// --- atf_amc.FUnitSort.tary.Remove
9206// Remove item by index. If index outside of range, do nothing.
9207void atf_amc::tary_Remove(atf_amc::FUnitSort& parent, u32 i) {
9208 u32 lim = parent.tary_n;
9209 atf_amc::TypeA *elems = parent.tary_elems;
9210 if (i < lim) {
9211 elems[i].~TypeA(); // destroy element
9212 memmove(elems + i, elems + (i + 1), sizeof(atf_amc::TypeA) * (lim - (i + 1)));
9213 parent.tary_n = lim - 1;
9214 }
9215}
9216
9217// --- atf_amc.FUnitSort.tary.RemoveAll
9218void atf_amc::tary_RemoveAll(atf_amc::FUnitSort& parent) {
9219 u32 n = parent.tary_n;
9220 while (n > 0) {
9221 n -= 1;
9222 parent.tary_elems[n].~TypeA();
9223 parent.tary_n = n;
9224 }
9225}
9226
9227// --- atf_amc.FUnitSort.tary.RemoveLast
9228// Delete last element of array. Do nothing if array is empty.
9229void atf_amc::tary_RemoveLast(atf_amc::FUnitSort& parent) {
9230 u64 n = parent.tary_n;
9231 if (n > 0) {
9232 n -= 1;
9233 tary_qFind(parent, u64(n)).~TypeA();
9234 parent.tary_n = n;
9235 }
9236}
9237
9238// --- atf_amc.FUnitSort.tary.AbsReserve
9239// Make sure N elements fit in array. Process dies if out of memory
9240void atf_amc::tary_AbsReserve(atf_amc::FUnitSort& parent, int n) {
9241 u32 old_max = parent.tary_max;
9242 if (n > i32(old_max)) {
9243 u32 new_max = i32_Max(i32_Max(old_max * 2, n), 4);
9244 void *new_mem = algo_lib::malloc_ReallocMem(parent.tary_elems, old_max * sizeof(atf_amc::TypeA), new_max * sizeof(atf_amc::TypeA));
9245 if (UNLIKELY(!new_mem)) {
9246 FatalErrorExit("atf_amc.tary_nomem field:atf_amc.FUnitSort.tary comment:'out of memory'");
9247 }
9248 parent.tary_elems = (atf_amc::TypeA*)new_mem;
9249 parent.tary_max = new_max;
9250 }
9251}
9252
9253// --- atf_amc.FUnitSort.tary.Setary
9254// Copy contents of RHS to PARENT.
9255void atf_amc::tary_Setary(atf_amc::FUnitSort& parent, atf_amc::FUnitSort &rhs) {
9256 tary_RemoveAll(parent);
9257 int nnew = rhs.tary_n;
9258 tary_Reserve(parent, nnew); // reserve space
9259 for (int i = 0; i < nnew; i++) { // copy elements over
9260 new (parent.tary_elems + i) atf_amc::TypeA(tary_qFind(rhs, i));
9261 parent.tary_n = i + 1;
9262 }
9263}
9264
9265// --- atf_amc.FUnitSort.tary.Setary2
9266// Copy specified array into tary, discarding previous contents.
9267// If the RHS argument aliases the array (refers to the same memory), throw exception.
9268void atf_amc::tary_Setary(atf_amc::FUnitSort& parent, const algo::aryptr<atf_amc::TypeA> &rhs) {
9269 tary_RemoveAll(parent);
9270 tary_Addary(parent, rhs);
9271}
9272
9273// --- atf_amc.FUnitSort.tary.AllocNVal
9274// Reserve space. Insert N elements at the end of the array, return pointer to array
9275algo::aryptr<atf_amc::TypeA> atf_amc::tary_AllocNVal(atf_amc::FUnitSort& parent, int n_elems, const atf_amc::TypeA& val) {
9276 tary_Reserve(parent, n_elems);
9277 int old_n = parent.tary_n;
9278 int new_n = old_n + n_elems;
9279 atf_amc::TypeA *elems = parent.tary_elems;
9280 for (int i = old_n; i < new_n; i++) {
9281 new (elems + i) atf_amc::TypeA(val);
9282 }
9283 parent.tary_n = new_n;
9284 return algo::aryptr<atf_amc::TypeA>(elems + old_n, n_elems);
9285}
9286
9287// --- atf_amc.FUnitSort.tary.ReadStrptrMaybe
9288// A single element is read from input string and appended to the array.
9289// If the string contains an error, the array is untouched.
9290// Function returns success value.
9291bool atf_amc::tary_ReadStrptrMaybe(atf_amc::FUnitSort& parent, algo::strptr in_str) {
9292 bool retval = true;
9293 atf_amc::TypeA &elem = tary_Alloc(parent);
9294 retval = atf_amc::TypeA_ReadStrptrMaybe(elem, in_str);
9295 if (!retval) {
9296 tary_RemoveLast(parent);
9297 }
9298 return retval;
9299}
9300
9301// --- atf_amc.FUnitSort.tary.Swap
9302// Swap values elem_a and elem_b
9303inline static void atf_amc::tary_Swap(atf_amc::TypeA &elem_a, atf_amc::TypeA &elem_b) {
9304 u8 temp[sizeof(atf_amc::TypeA)];
9305 memcpy(&temp , &elem_a, sizeof(atf_amc::TypeA));
9306 memcpy(&elem_a, &elem_b, sizeof(atf_amc::TypeA));
9307 memcpy(&elem_b, &temp , sizeof(atf_amc::TypeA));
9308}
9309
9310// --- atf_amc.FUnitSort.tary.Rotleft
9311// Left circular shift of three-tuple
9312inline static void atf_amc::tary_Rotleft(atf_amc::TypeA &elem_a, atf_amc::TypeA &elem_b, atf_amc::TypeA &elem_c) {
9313 u8 temp[sizeof(atf_amc::TypeA)];
9314 memcpy(&temp, &elem_a , sizeof(atf_amc::TypeA));
9315 memcpy(&elem_a , &elem_b , sizeof(atf_amc::TypeA));
9316 memcpy(&elem_b , &elem_c , sizeof(atf_amc::TypeA));
9317 memcpy(&elem_c , &temp, sizeof(atf_amc::TypeA));
9318}
9319
9320// --- atf_amc.FUnitSort.tary.Lt
9321// Compare values elem_a and elem_b
9322// The comparison function must be anti-symmetric: if a>b, then !(b>a).
9323// If not, mayhem results.
9324static bool atf_amc::tary_Lt(atf_amc::TypeA &elem_a, atf_amc::TypeA &elem_b) {
9325 bool ret;
9326 ret = elem_a.typea < elem_b.typea;
9327 return ret;
9328}
9329
9330// --- atf_amc.FUnitSort.tary.SortedQ
9331// Verify whether array is sorted
9332bool atf_amc::tary_SortedQ(atf_amc::FUnitSort& parent) {
9333 atf_amc::TypeA *elems = tary_Getary(parent).elems;
9334 int n = tary_N(parent);
9335 for (int i = 1; i < n; i++) {
9336 if (tary_Lt(elems[i], elems[i-1])) {
9337 return false;
9338 }
9339 }
9340 return true;
9341}
9342
9343// --- atf_amc.FUnitSort.tary.IntInsertionSort
9344// Internal insertion sort
9345static void atf_amc::tary_IntInsertionSort(atf_amc::TypeA *elems, int n) {
9346 for (int i = 1; i < n; ++i) {
9347 int j = i;
9348 // find the spot for ith element.
9349 while (j>0 && tary_Lt(elems[i], elems[j-1])) {
9350 j--;
9351 }
9352 if (j<i) {
9353 u8 tmp[sizeof(atf_amc::TypeA)];
9354 memcpy (tmp , &elems[i], sizeof(atf_amc::TypeA) );
9355 memmove(&elems[j+1], &elems[j], sizeof(atf_amc::TypeA)*(i-j));
9356 memcpy (&elems[j] , tmp , sizeof(atf_amc::TypeA) );
9357 }
9358 }
9359}
9360
9361// --- atf_amc.FUnitSort.tary.IntHeapSort
9362// Internal heap sort
9363static void atf_amc::tary_IntHeapSort(atf_amc::TypeA *elems, int n) {
9364 // construct max-heap.
9365 // k=current element
9366 // j=parent element
9367 for (int i = 1; i < n; i++) {
9368 int k=i;
9369 int j=(i-1)/2;
9370 while (tary_Lt(elems[j], elems[k])) {
9371 tary_Swap(elems[k],elems[j]);
9372 k=j;
9373 j=(k-1)/2;
9374 }
9375 }
9376 // remove elements from heap one-by-one,
9377 // deposit them in reverse order starting at the end of ARY.
9378 for (int i = n - 1; i>=0; i--) {
9379 int k = 0;
9380 int l = 1;
9381 while (l<i) {
9382 l += l<i-1 && tary_Lt(elems[l], elems[l+1]);
9383 if (tary_Lt(elems[l], elems[i])) {
9384 break;
9385 }
9386 tary_Swap(elems[k], elems[l]);
9387 k = l;
9388 l = k*2+1;
9389 }
9390 if (i != k) {
9391 tary_Swap(elems[i],elems[k]);
9392 }
9393 }
9394}
9395
9396// --- atf_amc.FUnitSort.tary.IntQuickSort
9397// Quick sort engine
9398static void atf_amc::tary_IntQuickSort(atf_amc::TypeA *elems, int n, int depth) {
9399 while (n>16) {
9400 // detect degenerate case and revert to heap sort
9401 if (depth==0) {
9402 tary_IntHeapSort(elems,n);
9403 return;
9404 }
9405 // elements to sort initially to determine pivot.
9406 // choose pp=n/2 in case the input is already sorted.
9407 int pi = 0;
9408 int pp = n/2;
9409 int pj = n-1;
9410 // insertion sort for 1st, middle and last element
9411 if (tary_Lt(elems[pp], elems[pi])) {
9412 tary_Swap(elems[pi], elems[pp]);
9413 }
9414 if (tary_Lt(elems[pj], elems[pp])) {
9415 if (tary_Lt(elems[pj], elems[pi])) {
9416 tary_Rotleft(elems[pi], elems[pj], elems[pp]);
9417 } else {
9418 tary_Swap(elems[pj], elems[pp]);
9419 }
9420 }
9421 // deposit pivot near the end of the array and skip it.
9422 tary_Swap(elems[--pj], elems[pp]);
9423 // reference to pivot
9424 atf_amc::TypeA &pivot = elems[pj];
9425 for(;;){
9426 while (tary_Lt(elems[++pi], pivot)) {
9427 }
9428 while (tary_Lt(pivot, elems[--pj])) {
9429 }
9430 if (pj <= pi) {
9431 break;
9432 }
9433 tary_Swap(elems[pi],elems[pj]);
9434 }
9435 depth -= 1;
9436 tary_IntQuickSort(elems, pi, depth);
9437 elems += pi;
9438 n -= pi;
9439 }
9440 // sort the remainder of this section
9441 tary_IntInsertionSort(elems,n);
9442}
9443
9444// --- atf_amc.FUnitSort.tary.InsertionSort
9445// Insertion sort
9446void atf_amc::tary_InsertionSort(atf_amc::FUnitSort& parent) {
9447 atf_amc::TypeA *elems = tary_Getary(parent).elems;
9448 int n = tary_N(parent);
9449 tary_IntInsertionSort(elems, n);
9450}
9451
9452// --- atf_amc.FUnitSort.tary.HeapSort
9453// Heap sort
9454void atf_amc::tary_HeapSort(atf_amc::FUnitSort& parent) {
9455 atf_amc::TypeA *elems = tary_Getary(parent).elems;
9456 int n = tary_N(parent);
9457 tary_IntHeapSort(elems, n);
9458}
9459
9460// --- atf_amc.FUnitSort.tary.QuickSort
9461// Quick sort
9462void atf_amc::tary_QuickSort(atf_amc::FUnitSort& parent) {
9463 // compute max recursion depth based on number of elements in the array
9464 int max_depth = algo::CeilingLog2(u32(tary_N(parent) + 1)) + 3;
9465 atf_amc::TypeA *elems = tary_Getary(parent).elems;
9466 int n = tary_N(parent);
9467 tary_IntQuickSort(elems, n, max_depth);
9468}
9469
9470// --- atf_amc.FUnitSort.c_ptrary.Insert
9471// Insert pointer to row into array. Row must not already be in array.
9472// If pointer is already in the array, it may be inserted twice.
9473void atf_amc::c_ptrary_Insert(atf_amc::FUnitSort& parent, atf_amc::TypeA& row) {
9474 // reserve space
9475 c_ptrary_Reserve(parent, 1);
9476 u32 n = parent.c_ptrary_n;
9477 u32 at = n;
9478 atf_amc::TypeA* *elems = parent.c_ptrary_elems;
9479 elems[at] = &row;
9480 parent.c_ptrary_n = n+1;
9481
9482}
9483
9484// --- atf_amc.FUnitSort.c_ptrary.ScanInsertMaybe
9485// Insert pointer to row in array.
9486// If row is already in the array, do nothing.
9487// Linear search is used to locate the element.
9488// Return value: whether element was inserted into array.
9489bool atf_amc::c_ptrary_ScanInsertMaybe(atf_amc::FUnitSort& parent, atf_amc::TypeA& row) {
9490 bool retval = true;
9491 u32 n = parent.c_ptrary_n;
9492 for (u32 i = 0; i < n; i++) {
9493 if (parent.c_ptrary_elems[i] == &row) {
9494 retval = false;
9495 break;
9496 }
9497 }
9498 if (retval) {
9499 // reserve space
9500 c_ptrary_Reserve(parent, 1);
9501 parent.c_ptrary_elems[n] = &row;
9502 parent.c_ptrary_n = n+1;
9503 }
9504 return retval;
9505}
9506
9507// --- atf_amc.FUnitSort.c_ptrary.Remove
9508// Find element using linear scan. If element is in array, remove, otherwise do nothing
9509void atf_amc::c_ptrary_Remove(atf_amc::FUnitSort& parent, atf_amc::TypeA& row) {
9510 int lim = parent.c_ptrary_n;
9511 atf_amc::TypeA* *elems = parent.c_ptrary_elems;
9512 // search backward, so that most recently added element is found first.
9513 // if found, shift array.
9514 for (int i = lim-1; i>=0; i--) {
9515 atf_amc::TypeA* elem = elems[i]; // fetch element
9516 if (elem == &row) {
9517 int j = i + 1;
9518 size_t nbytes = sizeof(atf_amc::TypeA*) * (lim - j);
9519 memmove(elems + i, elems + j, nbytes);
9520 parent.c_ptrary_n = lim - 1;
9521 break;
9522 }
9523 }
9524}
9525
9526// --- atf_amc.FUnitSort.c_ptrary.Reserve
9527// Reserve space in index for N more elements;
9528void atf_amc::c_ptrary_Reserve(atf_amc::FUnitSort& parent, u32 n) {
9529 u32 old_max = parent.c_ptrary_max;
9530 if (UNLIKELY(parent.c_ptrary_n + n > old_max)) {
9531 u32 new_max = u32_Max(4, old_max * 2);
9532 u32 old_size = old_max * sizeof(atf_amc::TypeA*);
9533 u32 new_size = new_max * sizeof(atf_amc::TypeA*);
9534 void *new_mem = algo_lib::malloc_ReallocMem(parent.c_ptrary_elems, old_size, new_size);
9535 if (UNLIKELY(!new_mem)) {
9536 FatalErrorExit("atf_amc.out_of_memory field:atf_amc.FUnitSort.c_ptrary");
9537 }
9538 parent.c_ptrary_elems = (atf_amc::TypeA**)new_mem;
9539 parent.c_ptrary_max = new_max;
9540 }
9541}
9542
9543// --- atf_amc.FUnitSort.c_ptrary.Swap
9544// Swap values elem_a and elem_b
9545inline static void atf_amc::c_ptrary_Swap(atf_amc::TypeA* &elem_a, atf_amc::TypeA* &elem_b) {
9546 atf_amc::TypeA *temp = elem_a;
9547 elem_a = elem_b;
9548 elem_b = temp;
9549}
9550
9551// --- atf_amc.FUnitSort.c_ptrary.Rotleft
9552// Left circular shift of three-tuple
9553inline static void atf_amc::c_ptrary_Rotleft(atf_amc::TypeA* &elem_a, atf_amc::TypeA* &elem_b, atf_amc::TypeA* &elem_c) {
9554 atf_amc::TypeA *temp = elem_a;
9555 elem_a = elem_b;
9556 elem_b = elem_c;
9557 elem_c = temp;
9558}
9559
9560// --- atf_amc.FUnitSort.c_ptrary.Lt
9561// Compare values elem_a and elem_b
9562// The comparison function must be anti-symmetric: if a>b, then !(b>a).
9563// If not, mayhem results.
9564static bool atf_amc::c_ptrary_Lt(atf_amc::TypeA &elem_a, atf_amc::TypeA &elem_b) {
9565 bool ret;
9566 ret = elem_a.typea < elem_b.typea;
9567 return ret;
9568}
9569
9570// --- atf_amc.FUnitSort.c_ptrary.SortedQ
9571// Verify whether array is sorted
9572bool atf_amc::c_ptrary_SortedQ(atf_amc::FUnitSort& parent) {
9573 atf_amc::TypeA* *elems = c_ptrary_Getary(parent).elems;
9574 int n = c_ptrary_N(parent);
9575 for (int i = 1; i < n; i++) {
9576 if (c_ptrary_Lt(*elems[i], *elems[i-1])) {
9577 return false;
9578 }
9579 }
9580 return true;
9581}
9582
9583// --- atf_amc.FUnitSort.c_ptrary.IntInsertionSort
9584// Internal insertion sort
9585static void atf_amc::c_ptrary_IntInsertionSort(atf_amc::TypeA* *elems, int n) {
9586 for (int i = 1; i < n; ++i) {
9587 int j = i;
9588 atf_amc::TypeA *tmp = elems[i];
9589 // shift elements up by one
9590 if (c_ptrary_Lt(*tmp, *elems[j-1])) {
9591 do {
9592 elems[j] = elems[j-1];
9593 j--;
9594 } while (j>0 && c_ptrary_Lt(*tmp, *elems[j-1]));
9595 elems[j] = tmp;
9596 }
9597 }
9598}
9599
9600// --- atf_amc.FUnitSort.c_ptrary.IntHeapSort
9601// Internal heap sort
9602static void atf_amc::c_ptrary_IntHeapSort(atf_amc::TypeA* *elems, int n) {
9603 // construct max-heap.
9604 // k=current element
9605 // j=parent element
9606 for (int i = 1; i < n; i++) {
9607 int k=i;
9608 int j=(i-1)/2;
9609 while (c_ptrary_Lt(*elems[j], *elems[k])) {
9610 c_ptrary_Swap(elems[k],elems[j]);
9611 k=j;
9612 j=(k-1)/2;
9613 }
9614 }
9615 // remove elements from heap one-by-one,
9616 // deposit them in reverse order starting at the end of ARY.
9617 for (int i = n - 1; i>=0; i--) {
9618 int k = 0;
9619 int l = 1;
9620 while (l<i) {
9621 l += l<i-1 && c_ptrary_Lt(*elems[l], *elems[l+1]);
9622 if (c_ptrary_Lt(*elems[l], *elems[i])) {
9623 break;
9624 }
9625 c_ptrary_Swap(elems[k], elems[l]);
9626 k = l;
9627 l = k*2+1;
9628 }
9629 if (i != k) {
9630 c_ptrary_Swap(elems[i],elems[k]);
9631 }
9632 }
9633}
9634
9635// --- atf_amc.FUnitSort.c_ptrary.IntQuickSort
9636// Quick sort engine
9637static void atf_amc::c_ptrary_IntQuickSort(atf_amc::TypeA* *elems, int n, int depth) {
9638 while (n>16) {
9639 // detect degenerate case and revert to heap sort
9640 if (depth==0) {
9641 c_ptrary_IntHeapSort(elems,n);
9642 return;
9643 }
9644 // elements to sort initially to determine pivot.
9645 // choose pp=n/2 in case the input is already sorted.
9646 int pi = 0;
9647 int pp = n/2;
9648 int pj = n-1;
9649 // insertion sort for 1st, middle and last element
9650 if (c_ptrary_Lt(*elems[pp], *elems[pi])) {
9651 c_ptrary_Swap(elems[pi], elems[pp]);
9652 }
9653 if (c_ptrary_Lt(*elems[pj], *elems[pp])) {
9654 if (c_ptrary_Lt(*elems[pj], *elems[pi])) {
9655 c_ptrary_Rotleft(elems[pi], elems[pj], elems[pp]);
9656 } else {
9657 c_ptrary_Swap(elems[pj], elems[pp]);
9658 }
9659 }
9660 // deposit pivot near the end of the array and skip it.
9661 c_ptrary_Swap(elems[--pj], elems[pp]);
9662 // copy pivot into temporary variable
9663 atf_amc::TypeA *pivot = elems[pj];
9664 for(;;){
9665 while (c_ptrary_Lt(*elems[++pi], *pivot)) {
9666 }
9667 while (c_ptrary_Lt(*pivot, *elems[--pj])) {
9668 }
9669 if (pj <= pi) {
9670 break;
9671 }
9672 c_ptrary_Swap(elems[pi],elems[pj]);
9673 }
9674 depth -= 1;
9675 c_ptrary_IntQuickSort(elems, pi, depth);
9676 elems += pi;
9677 n -= pi;
9678 }
9679 // sort the remainder of this section
9680 c_ptrary_IntInsertionSort(elems,n);
9681}
9682
9683// --- atf_amc.FUnitSort.c_ptrary.InsertionSort
9684// Insertion sort
9685void atf_amc::c_ptrary_InsertionSort(atf_amc::FUnitSort& parent) {
9686 atf_amc::TypeA* *elems = c_ptrary_Getary(parent).elems;
9687 int n = c_ptrary_N(parent);
9688 c_ptrary_IntInsertionSort(elems, n);
9689}
9690
9691// --- atf_amc.FUnitSort.c_ptrary.HeapSort
9692// Heap sort
9693void atf_amc::c_ptrary_HeapSort(atf_amc::FUnitSort& parent) {
9694 atf_amc::TypeA* *elems = c_ptrary_Getary(parent).elems;
9695 int n = c_ptrary_N(parent);
9696 c_ptrary_IntHeapSort(elems, n);
9697}
9698
9699// --- atf_amc.FUnitSort.c_ptrary.QuickSort
9700// Quick sort
9701void atf_amc::c_ptrary_QuickSort(atf_amc::FUnitSort& parent) {
9702 // compute max recursion depth based on number of elements in the array
9703 int max_depth = algo::CeilingLog2(u32(c_ptrary_N(parent) + 1)) + 3;
9704 atf_amc::TypeA* *elems = c_ptrary_Getary(parent).elems;
9705 int n = c_ptrary_N(parent);
9706 c_ptrary_IntQuickSort(elems, n, max_depth);
9707}
9708
9709// --- atf_amc.FUnitSort.fixary.ReadStrptrMaybe
9710// Read array from string
9711// Convert string to field. Return success value
9712bool atf_amc::fixary_ReadStrptrMaybe(atf_amc::FUnitSort& parent, algo::strptr in_str) {
9713 bool retval = true;
9714 if (100>0) {
9715 retval = atf_amc::TypeA_ReadStrptrMaybe(parent.fixary_elems[0], in_str);
9716 }
9717 return retval;
9718}
9719
9720// --- atf_amc.FUnitSort.fixary.Swap
9721// Swap values elem_a and elem_b
9722inline static void atf_amc::fixary_Swap(atf_amc::TypeA &elem_a, atf_amc::TypeA &elem_b) {
9723 u8 temp[sizeof(atf_amc::TypeA)];
9724 memcpy(&temp , &elem_a, sizeof(atf_amc::TypeA));
9725 memcpy(&elem_a, &elem_b, sizeof(atf_amc::TypeA));
9726 memcpy(&elem_b, &temp , sizeof(atf_amc::TypeA));
9727}
9728
9729// --- atf_amc.FUnitSort.fixary.Rotleft
9730// Left circular shift of three-tuple
9731inline static void atf_amc::fixary_Rotleft(atf_amc::TypeA &elem_a, atf_amc::TypeA &elem_b, atf_amc::TypeA &elem_c) {
9732 u8 temp[sizeof(atf_amc::TypeA)];
9733 memcpy(&temp, &elem_a , sizeof(atf_amc::TypeA));
9734 memcpy(&elem_a , &elem_b , sizeof(atf_amc::TypeA));
9735 memcpy(&elem_b , &elem_c , sizeof(atf_amc::TypeA));
9736 memcpy(&elem_c , &temp, sizeof(atf_amc::TypeA));
9737}
9738
9739// --- atf_amc.FUnitSort.fixary.Lt
9740// Compare values elem_a and elem_b
9741// The comparison function must be anti-symmetric: if a>b, then !(b>a).
9742// If not, mayhem results.
9743static bool atf_amc::fixary_Lt(atf_amc::TypeA &elem_a, atf_amc::TypeA &elem_b) {
9744 bool ret;
9745 ret = elem_a.typea < elem_b.typea;
9746 return ret;
9747}
9748
9749// --- atf_amc.FUnitSort.fixary.SortedQ
9750// Verify whether array is sorted
9751bool atf_amc::fixary_SortedQ(atf_amc::FUnitSort& parent) {
9752 atf_amc::TypeA *elems = fixary_Getary(parent).elems;
9753 int n = fixary_N(parent);
9754 for (int i = 1; i < n; i++) {
9755 if (fixary_Lt(elems[i], elems[i-1])) {
9756 return false;
9757 }
9758 }
9759 return true;
9760}
9761
9762// --- atf_amc.FUnitSort.fixary.IntInsertionSort
9763// Internal insertion sort
9764static void atf_amc::fixary_IntInsertionSort(atf_amc::TypeA *elems, int n) {
9765 for (int i = 1; i < n; ++i) {
9766 int j = i;
9767 // find the spot for ith element.
9768 while (j>0 && fixary_Lt(elems[i], elems[j-1])) {
9769 j--;
9770 }
9771 if (j<i) {
9772 u8 tmp[sizeof(atf_amc::TypeA)];
9773 memcpy (tmp , &elems[i], sizeof(atf_amc::TypeA) );
9774 memmove(&elems[j+1], &elems[j], sizeof(atf_amc::TypeA)*(i-j));
9775 memcpy (&elems[j] , tmp , sizeof(atf_amc::TypeA) );
9776 }
9777 }
9778}
9779
9780// --- atf_amc.FUnitSort.fixary.IntHeapSort
9781// Internal heap sort
9782static void atf_amc::fixary_IntHeapSort(atf_amc::TypeA *elems, int n) {
9783 // construct max-heap.
9784 // k=current element
9785 // j=parent element
9786 for (int i = 1; i < n; i++) {
9787 int k=i;
9788 int j=(i-1)/2;
9789 while (fixary_Lt(elems[j], elems[k])) {
9790 fixary_Swap(elems[k],elems[j]);
9791 k=j;
9792 j=(k-1)/2;
9793 }
9794 }
9795 // remove elements from heap one-by-one,
9796 // deposit them in reverse order starting at the end of ARY.
9797 for (int i = n - 1; i>=0; i--) {
9798 int k = 0;
9799 int l = 1;
9800 while (l<i) {
9801 l += l<i-1 && fixary_Lt(elems[l], elems[l+1]);
9802 if (fixary_Lt(elems[l], elems[i])) {
9803 break;
9804 }
9805 fixary_Swap(elems[k], elems[l]);
9806 k = l;
9807 l = k*2+1;
9808 }
9809 if (i != k) {
9810 fixary_Swap(elems[i],elems[k]);
9811 }
9812 }
9813}
9814
9815// --- atf_amc.FUnitSort.fixary.IntQuickSort
9816// Quick sort engine
9817static void atf_amc::fixary_IntQuickSort(atf_amc::TypeA *elems, int n, int depth) {
9818 while (n>16) {
9819 // detect degenerate case and revert to heap sort
9820 if (depth==0) {
9821 fixary_IntHeapSort(elems,n);
9822 return;
9823 }
9824 // elements to sort initially to determine pivot.
9825 // choose pp=n/2 in case the input is already sorted.
9826 int pi = 0;
9827 int pp = n/2;
9828 int pj = n-1;
9829 // insertion sort for 1st, middle and last element
9830 if (fixary_Lt(elems[pp], elems[pi])) {
9831 fixary_Swap(elems[pi], elems[pp]);
9832 }
9833 if (fixary_Lt(elems[pj], elems[pp])) {
9834 if (fixary_Lt(elems[pj], elems[pi])) {
9835 fixary_Rotleft(elems[pi], elems[pj], elems[pp]);
9836 } else {
9837 fixary_Swap(elems[pj], elems[pp]);
9838 }
9839 }
9840 // deposit pivot near the end of the array and skip it.
9841 fixary_Swap(elems[--pj], elems[pp]);
9842 // reference to pivot
9843 atf_amc::TypeA &pivot = elems[pj];
9844 for(;;){
9845 while (fixary_Lt(elems[++pi], pivot)) {
9846 }
9847 while (fixary_Lt(pivot, elems[--pj])) {
9848 }
9849 if (pj <= pi) {
9850 break;
9851 }
9852 fixary_Swap(elems[pi],elems[pj]);
9853 }
9854 depth -= 1;
9855 fixary_IntQuickSort(elems, pi, depth);
9856 elems += pi;
9857 n -= pi;
9858 }
9859 // sort the remainder of this section
9860 fixary_IntInsertionSort(elems,n);
9861}
9862
9863// --- atf_amc.FUnitSort.fixary.InsertionSort
9864// Insertion sort
9865void atf_amc::fixary_InsertionSort(atf_amc::FUnitSort& parent) {
9866 atf_amc::TypeA *elems = fixary_Getary(parent).elems;
9867 int n = fixary_N(parent);
9868 fixary_IntInsertionSort(elems, n);
9869}
9870
9871// --- atf_amc.FUnitSort.fixary.HeapSort
9872// Heap sort
9873void atf_amc::fixary_HeapSort(atf_amc::FUnitSort& parent) {
9874 atf_amc::TypeA *elems = fixary_Getary(parent).elems;
9875 int n = fixary_N(parent);
9876 fixary_IntHeapSort(elems, n);
9877}
9878
9879// --- atf_amc.FUnitSort.fixary.QuickSort
9880// Quick sort
9881void atf_amc::fixary_QuickSort(atf_amc::FUnitSort& parent) {
9882 // compute max recursion depth based on number of elements in the array
9883 int max_depth = algo::CeilingLog2(u32(fixary_N(parent) + 1)) + 3;
9884 atf_amc::TypeA *elems = fixary_Getary(parent).elems;
9885 int n = fixary_N(parent);
9886 fixary_IntQuickSort(elems, n, max_depth);
9887}
9888
9889// --- atf_amc.FUnitSort.fixary.XrefMaybe
9890// Insert row into all appropriate indices. If error occurs, store error
9891// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
9892bool atf_amc::fixary_XrefMaybe(atf_amc::TypeA &row) {
9893 bool retval = true;
9894 (void)row;
9895 return retval;
9896}
9897
9898// --- atf_amc.FUnitSort..Uninit
9899void atf_amc::FUnitSort_Uninit(atf_amc::FUnitSort& parent) {
9900 atf_amc::FUnitSort &row = parent; (void)row;
9901
9902 // atf_amc.FUnitSort.c_ptrary.Uninit (Ptrary) //
9903 algo_lib::malloc_FreeMem(parent.c_ptrary_elems, sizeof(atf_amc::TypeA*)*parent.c_ptrary_max); // (atf_amc.FUnitSort.c_ptrary)
9904
9905 // atf_amc.FUnitSort.tary.Uninit (Tary) //
9906 // remove all elements from atf_amc.FUnitSort.tary
9907 tary_RemoveAll(parent);
9908 // free memory for Tary atf_amc.FUnitSort.tary
9909 algo_lib::malloc_FreeMem(parent.tary_elems, sizeof(atf_amc::TypeA)*parent.tary_max); // (atf_amc.FUnitSort.tary)
9910}
9911
9912// --- atf_amc.FieldId.value.ToCstr
9913// Convert numeric value of field to one of predefined string constants.
9914// If string is found, return a static C string. Otherwise, return NULL.
9915const char* atf_amc::value_ToCstr(const atf_amc::FieldId& parent) {
9916 const char *ret = NULL;
9917 switch(value_GetEnum(parent)) {
9918 case atf_amc_FieldId_value : ret = "value"; break;
9919 case atf_amc_FieldId_bit1 : ret = "bit1"; break;
9920 case atf_amc_FieldId_bits5 : ret = "bits5"; break;
9921 case atf_amc_FieldId_bit0 : ret = "bit0"; break;
9922 case atf_amc_FieldId_freebool : ret = "freebool"; break;
9923 case atf_amc_FieldId_attr1 : ret = "attr1"; break;
9924 case atf_amc_FieldId_attr2 : ret = "attr2"; break;
9925 case atf_amc_FieldId_strval : ret = "strval"; break;
9926 case atf_amc_FieldId_strval2 : ret = "strval2"; break;
9927 case atf_amc_FieldId_dateval : ret = "dateval"; break;
9928 case atf_amc_FieldId_intval : ret = "intval"; break;
9929 case atf_amc_FieldId_fixary : ret = "fixary"; break;
9930 case atf_amc_FieldId_inlary : ret = "inlary"; break;
9931 case atf_amc_FieldId_len : ret = "len"; break;
9932 case atf_amc_FieldId_type : ret = "type"; break;
9933 case atf_amc_FieldId_length : ret = "length"; break;
9934 case atf_amc_FieldId_base : ret = "base"; break;
9935 case atf_amc_FieldId_a : ret = "a"; break;
9936 case atf_amc_FieldId_b : ret = "b"; break;
9937 case atf_amc_FieldId_o : ret = "o"; break;
9938 case atf_amc_FieldId_v : ret = "v"; break;
9939 case atf_amc_FieldId_typeg : ret = "typeg"; break;
9940 case atf_amc_FieldId_optg : ret = "optg"; break;
9941 case atf_amc_FieldId_present : ret = "present"; break;
9942 case atf_amc_FieldId_assigned : ret = "assigned"; break;
9943 case atf_amc_FieldId_nullable : ret = "nullable"; break;
9944 case atf_amc_FieldId_value1 : ret = "value1"; break;
9945 case atf_amc_FieldId_value2 : ret = "value2"; break;
9946 case atf_amc_FieldId_value3 : ret = "value3"; break;
9947 case atf_amc_FieldId_value4 : ret = "value4"; break;
9948 case atf_amc_FieldId_value5 : ret = "value5"; break;
9949 case atf_amc_FieldId_value6 : ret = "value6"; break;
9950 case atf_amc_FieldId_value7 : ret = "value7"; break;
9951 case atf_amc_FieldId_pmask : ret = "pmask"; break;
9952 case atf_amc_FieldId_value21 : ret = "value21"; break;
9953 case atf_amc_FieldId_value22 : ret = "value22"; break;
9954 case atf_amc_FieldId_value23 : ret = "value23"; break;
9955 case atf_amc_FieldId_value24 : ret = "value24"; break;
9956 case atf_amc_FieldId_value25 : ret = "value25"; break;
9957 case atf_amc_FieldId_value26 : ret = "value26"; break;
9958 case atf_amc_FieldId_value20 : ret = "value20"; break;
9959 case atf_amc_FieldId_value28 : ret = "value28"; break;
9960 case atf_amc_FieldId_value29 : ret = "value29"; break;
9961 case atf_amc_FieldId_value30 : ret = "value30"; break;
9962 case atf_amc_FieldId_value31 : ret = "value31"; break;
9963 case atf_amc_FieldId_value32 : ret = "value32"; break;
9964 case atf_amc_FieldId_value27 : ret = "value27"; break;
9965 case atf_amc_FieldId_value19 : ret = "value19"; break;
9966 case atf_amc_FieldId_value18 : ret = "value18"; break;
9967 case atf_amc_FieldId_value8 : ret = "value8"; break;
9968 case atf_amc_FieldId_value9 : ret = "value9"; break;
9969 case atf_amc_FieldId_value69 : ret = "value69"; break;
9970 case atf_amc_FieldId_value11 : ret = "value11"; break;
9971 case atf_amc_FieldId_value12 : ret = "value12"; break;
9972 case atf_amc_FieldId_value13 : ret = "value13"; break;
9973 case atf_amc_FieldId_value14 : ret = "value14"; break;
9974 case atf_amc_FieldId_value15 : ret = "value15"; break;
9975 case atf_amc_FieldId_value16 : ret = "value16"; break;
9976 case atf_amc_FieldId_value33 : ret = "value33"; break;
9977 case atf_amc_FieldId_value10 : ret = "value10"; break;
9978 case atf_amc_FieldId_value17 : ret = "value17"; break;
9979 case atf_amc_FieldId_value35 : ret = "value35"; break;
9980 case atf_amc_FieldId_value55 : ret = "value55"; break;
9981 case atf_amc_FieldId_value56 : ret = "value56"; break;
9982 case atf_amc_FieldId_value57 : ret = "value57"; break;
9983 case atf_amc_FieldId_value58 : ret = "value58"; break;
9984 case atf_amc_FieldId_value59 : ret = "value59"; break;
9985 case atf_amc_FieldId_value60 : ret = "value60"; break;
9986 case atf_amc_FieldId_value54 : ret = "value54"; break;
9987 case atf_amc_FieldId_value62 : ret = "value62"; break;
9988 case atf_amc_FieldId_value63 : ret = "value63"; break;
9989 case atf_amc_FieldId_value64 : ret = "value64"; break;
9990 case atf_amc_FieldId_value65 : ret = "value65"; break;
9991 case atf_amc_FieldId_value66 : ret = "value66"; break;
9992 case atf_amc_FieldId_value67 : ret = "value67"; break;
9993 case atf_amc_FieldId_value68 : ret = "value68"; break;
9994 case atf_amc_FieldId_value61 : ret = "value61"; break;
9995 case atf_amc_FieldId_value34 : ret = "value34"; break;
9996 case atf_amc_FieldId_value52 : ret = "value52"; break;
9997 case atf_amc_FieldId_value36 : ret = "value36"; break;
9998 case atf_amc_FieldId_value37 : ret = "value37"; break;
9999 case atf_amc_FieldId_value38 : ret = "value38"; break;
10000 case atf_amc_FieldId_value39 : ret = "value39"; break;
10001 case atf_amc_FieldId_value40 : ret = "value40"; break;
10002 case atf_amc_FieldId_value41 : ret = "value41"; break;
10003 case atf_amc_FieldId_value42 : ret = "value42"; break;
10004 case atf_amc_FieldId_value53 : ret = "value53"; break;
10005 case atf_amc_FieldId_value44 : ret = "value44"; break;
10006 case atf_amc_FieldId_value45 : ret = "value45"; break;
10007 case atf_amc_FieldId_value46 : ret = "value46"; break;
10008 case atf_amc_FieldId_value47 : ret = "value47"; break;
10009 case atf_amc_FieldId_value48 : ret = "value48"; break;
10010 case atf_amc_FieldId_value49 : ret = "value49"; break;
10011 case atf_amc_FieldId_value50 : ret = "value50"; break;
10012 case atf_amc_FieldId_value51 : ret = "value51"; break;
10013 case atf_amc_FieldId_value43 : ret = "value43"; break;
10014 case atf_amc_FieldId_value70 : ret = "value70"; break;
10015 case atf_amc_FieldId_value71 : ret = "value71"; break;
10016 case atf_amc_FieldId_ch : ret = "ch"; break;
10017 case atf_amc_FieldId_val1 : ret = "val1"; break;
10018 case atf_amc_FieldId_val2 : ret = "val2"; break;
10019 case atf_amc_FieldId_val3 : ret = "val3"; break;
10020 case atf_amc_FieldId_msghdr : ret = "msghdr"; break;
10021 case atf_amc_FieldId_payload : ret = "payload"; break;
10022 case atf_amc_FieldId_val : ret = "val"; break;
10023 case atf_amc_FieldId_text : ret = "text"; break;
10024 case atf_amc_FieldId_typea : ret = "typea"; break;
10025 case atf_amc_FieldId_j : ret = "j"; break;
10026 case atf_amc_FieldId_typec : ret = "typec"; break;
10027 case atf_amc_FieldId_typeh : ret = "typeh"; break;
10028 case atf_amc_FieldId_types : ret = "types"; break;
10029 case atf_amc_FieldId_comment : ret = "comment"; break;
10030 case atf_amc_FieldId_i : ret = "i"; break;
10031 case atf_amc_FieldId_k : ret = "k"; break;
10032 case atf_amc_FieldId_strval_regx : ret = "strval_regx"; break;
10033 case atf_amc_FieldId_strval2_regx : ret = "strval2_regx"; break;
10034 case atf_amc_FieldId_start_dateval : ret = "start_dateval"; break;
10035 case atf_amc_FieldId_end_dateval : ret = "end_dateval"; break;
10036 case atf_amc_FieldId_start_intval : ret = "start_intval"; break;
10037 case atf_amc_FieldId_end_intval : ret = "end_intval"; break;
10038 }
10039 return ret;
10040}
10041
10042// --- atf_amc.FieldId.value.Print
10043// Convert value to a string. First, attempt conversion to a known string.
10044// If no string matches, print value as a numeric value.
10045void atf_amc::value_Print(const atf_amc::FieldId& parent, algo::cstring &lhs) {
10046 const char *strval = value_ToCstr(parent);
10047 if (strval) {
10048 lhs << strval;
10049 } else {
10050 lhs << parent.value;
10051 }
10052}
10053
10054// --- atf_amc.FieldId.value.SetStrptrMaybe
10055// Convert string to field.
10056// If the string is invalid, do not modify field and return false.
10057// In case of success, return true
10058bool atf_amc::value_SetStrptrMaybe(atf_amc::FieldId& parent, algo::strptr rhs) {
10059 bool ret = false;
10060 switch (elems_N(rhs)) {
10061 case 1: {
10062 switch (u64(rhs[0])) {
10063 case 'a': {
10064 value_SetEnum(parent,atf_amc_FieldId_a); ret = true; break;
10065 }
10066 case 'b': {
10067 value_SetEnum(parent,atf_amc_FieldId_b); ret = true; break;
10068 }
10069 case 'i': {
10070 value_SetEnum(parent,atf_amc_FieldId_i); ret = true; break;
10071 }
10072 case 'j': {
10073 value_SetEnum(parent,atf_amc_FieldId_j); ret = true; break;
10074 }
10075 case 'k': {
10076 value_SetEnum(parent,atf_amc_FieldId_k); ret = true; break;
10077 }
10078 case 'o': {
10079 value_SetEnum(parent,atf_amc_FieldId_o); ret = true; break;
10080 }
10081 case 'v': {
10082 value_SetEnum(parent,atf_amc_FieldId_v); ret = true; break;
10083 }
10084 }
10085 break;
10086 }
10087 case 2: {
10088 switch (u64(algo::ReadLE16(rhs.elems))) {
10089 case LE_STR2('c','h'): {
10090 value_SetEnum(parent,atf_amc_FieldId_ch); ret = true; break;
10091 }
10092 }
10093 break;
10094 }
10095 case 3: {
10096 switch (u64(algo::ReadLE16(rhs.elems))|(u64(rhs[2])<<16)) {
10097 case LE_STR3('l','e','n'): {
10098 value_SetEnum(parent,atf_amc_FieldId_len); ret = true; break;
10099 }
10100 case LE_STR3('v','a','l'): {
10101 value_SetEnum(parent,atf_amc_FieldId_val); ret = true; break;
10102 }
10103 }
10104 break;
10105 }
10106 case 4: {
10107 switch (u64(algo::ReadLE32(rhs.elems))) {
10108 case LE_STR4('b','a','s','e'): {
10109 value_SetEnum(parent,atf_amc_FieldId_base); ret = true; break;
10110 }
10111 case LE_STR4('b','i','t','0'): {
10112 value_SetEnum(parent,atf_amc_FieldId_bit0); ret = true; break;
10113 }
10114 case LE_STR4('b','i','t','1'): {
10115 value_SetEnum(parent,atf_amc_FieldId_bit1); ret = true; break;
10116 }
10117 case LE_STR4('o','p','t','g'): {
10118 value_SetEnum(parent,atf_amc_FieldId_optg); ret = true; break;
10119 }
10120 case LE_STR4('t','e','x','t'): {
10121 value_SetEnum(parent,atf_amc_FieldId_text); ret = true; break;
10122 }
10123 case LE_STR4('t','y','p','e'): {
10124 value_SetEnum(parent,atf_amc_FieldId_type); ret = true; break;
10125 }
10126 case LE_STR4('v','a','l','1'): {
10127 value_SetEnum(parent,atf_amc_FieldId_val1); ret = true; break;
10128 }
10129 case LE_STR4('v','a','l','2'): {
10130 value_SetEnum(parent,atf_amc_FieldId_val2); ret = true; break;
10131 }
10132 case LE_STR4('v','a','l','3'): {
10133 value_SetEnum(parent,atf_amc_FieldId_val3); ret = true; break;
10134 }
10135 }
10136 break;
10137 }
10138 case 5: {
10139 switch (u64(algo::ReadLE32(rhs.elems))|(u64(rhs[4])<<32)) {
10140 case LE_STR5('a','t','t','r','1'): {
10141 value_SetEnum(parent,atf_amc_FieldId_attr1); ret = true; break;
10142 }
10143 case LE_STR5('a','t','t','r','2'): {
10144 value_SetEnum(parent,atf_amc_FieldId_attr2); ret = true; break;
10145 }
10146 case LE_STR5('b','i','t','s','5'): {
10147 value_SetEnum(parent,atf_amc_FieldId_bits5); ret = true; break;
10148 }
10149 case LE_STR5('p','m','a','s','k'): {
10150 value_SetEnum(parent,atf_amc_FieldId_pmask); ret = true; break;
10151 }
10152 case LE_STR5('t','y','p','e','a'): {
10153 value_SetEnum(parent,atf_amc_FieldId_typea); ret = true; break;
10154 }
10155 case LE_STR5('t','y','p','e','c'): {
10156 value_SetEnum(parent,atf_amc_FieldId_typec); ret = true; break;
10157 }
10158 case LE_STR5('t','y','p','e','g'): {
10159 value_SetEnum(parent,atf_amc_FieldId_typeg); ret = true; break;
10160 }
10161 case LE_STR5('t','y','p','e','h'): {
10162 value_SetEnum(parent,atf_amc_FieldId_typeh); ret = true; break;
10163 }
10164 case LE_STR5('t','y','p','e','s'): {
10165 value_SetEnum(parent,atf_amc_FieldId_types); ret = true; break;
10166 }
10167 case LE_STR5('v','a','l','u','e'): {
10168 value_SetEnum(parent,atf_amc_FieldId_value); ret = true; break;
10169 }
10170 }
10171 break;
10172 }
10173 case 6: {
10174 switch (u64(algo::ReadLE32(rhs.elems))|(u64(algo::ReadLE16(rhs.elems+4))<<32)) {
10175 case LE_STR6('f','i','x','a','r','y'): {
10176 value_SetEnum(parent,atf_amc_FieldId_fixary); ret = true; break;
10177 }
10178 case LE_STR6('i','n','l','a','r','y'): {
10179 value_SetEnum(parent,atf_amc_FieldId_inlary); ret = true; break;
10180 }
10181 case LE_STR6('i','n','t','v','a','l'): {
10182 value_SetEnum(parent,atf_amc_FieldId_intval); ret = true; break;
10183 }
10184 case LE_STR6('l','e','n','g','t','h'): {
10185 value_SetEnum(parent,atf_amc_FieldId_length); ret = true; break;
10186 }
10187 case LE_STR6('m','s','g','h','d','r'): {
10188 value_SetEnum(parent,atf_amc_FieldId_msghdr); ret = true; break;
10189 }
10190 case LE_STR6('s','t','r','v','a','l'): {
10191 value_SetEnum(parent,atf_amc_FieldId_strval); ret = true; break;
10192 }
10193 case LE_STR6('v','a','l','u','e','1'): {
10194 value_SetEnum(parent,atf_amc_FieldId_value1); ret = true; break;
10195 }
10196 case LE_STR6('v','a','l','u','e','2'): {
10197 value_SetEnum(parent,atf_amc_FieldId_value2); ret = true; break;
10198 }
10199 case LE_STR6('v','a','l','u','e','3'): {
10200 value_SetEnum(parent,atf_amc_FieldId_value3); ret = true; break;
10201 }
10202 case LE_STR6('v','a','l','u','e','4'): {
10203 value_SetEnum(parent,atf_amc_FieldId_value4); ret = true; break;
10204 }
10205 case LE_STR6('v','a','l','u','e','5'): {
10206 value_SetEnum(parent,atf_amc_FieldId_value5); ret = true; break;
10207 }
10208 case LE_STR6('v','a','l','u','e','6'): {
10209 value_SetEnum(parent,atf_amc_FieldId_value6); ret = true; break;
10210 }
10211 case LE_STR6('v','a','l','u','e','7'): {
10212 value_SetEnum(parent,atf_amc_FieldId_value7); ret = true; break;
10213 }
10214 case LE_STR6('v','a','l','u','e','8'): {
10215 value_SetEnum(parent,atf_amc_FieldId_value8); ret = true; break;
10216 }
10217 case LE_STR6('v','a','l','u','e','9'): {
10218 value_SetEnum(parent,atf_amc_FieldId_value9); ret = true; break;
10219 }
10220 }
10221 break;
10222 }
10223 case 7: {
10224 switch (u64(algo::ReadLE32(rhs.elems))|(u64(algo::ReadLE16(rhs.elems+4))<<32)|(u64(rhs[6])<<48)) {
10225 case LE_STR7('c','o','m','m','e','n','t'): {
10226 value_SetEnum(parent,atf_amc_FieldId_comment); ret = true; break;
10227 }
10228 case LE_STR7('d','a','t','e','v','a','l'): {
10229 value_SetEnum(parent,atf_amc_FieldId_dateval); ret = true; break;
10230 }
10231 case LE_STR7('p','a','y','l','o','a','d'): {
10232 value_SetEnum(parent,atf_amc_FieldId_payload); ret = true; break;
10233 }
10234 case LE_STR7('p','r','e','s','e','n','t'): {
10235 value_SetEnum(parent,atf_amc_FieldId_present); ret = true; break;
10236 }
10237 case LE_STR7('s','t','r','v','a','l','2'): {
10238 value_SetEnum(parent,atf_amc_FieldId_strval2); ret = true; break;
10239 }
10240 case LE_STR7('v','a','l','u','e','1','0'): {
10241 value_SetEnum(parent,atf_amc_FieldId_value10); ret = true; break;
10242 }
10243 case LE_STR7('v','a','l','u','e','1','1'): {
10244 value_SetEnum(parent,atf_amc_FieldId_value11); ret = true; break;
10245 }
10246 case LE_STR7('v','a','l','u','e','1','2'): {
10247 value_SetEnum(parent,atf_amc_FieldId_value12); ret = true; break;
10248 }
10249 case LE_STR7('v','a','l','u','e','1','3'): {
10250 value_SetEnum(parent,atf_amc_FieldId_value13); ret = true; break;
10251 }
10252 case LE_STR7('v','a','l','u','e','1','4'): {
10253 value_SetEnum(parent,atf_amc_FieldId_value14); ret = true; break;
10254 }
10255 case LE_STR7('v','a','l','u','e','1','5'): {
10256 value_SetEnum(parent,atf_amc_FieldId_value15); ret = true; break;
10257 }
10258 case LE_STR7('v','a','l','u','e','1','6'): {
10259 value_SetEnum(parent,atf_amc_FieldId_value16); ret = true; break;
10260 }
10261 case LE_STR7('v','a','l','u','e','1','7'): {
10262 value_SetEnum(parent,atf_amc_FieldId_value17); ret = true; break;
10263 }
10264 case LE_STR7('v','a','l','u','e','1','8'): {
10265 value_SetEnum(parent,atf_amc_FieldId_value18); ret = true; break;
10266 }
10267 case LE_STR7('v','a','l','u','e','1','9'): {
10268 value_SetEnum(parent,atf_amc_FieldId_value19); ret = true; break;
10269 }
10270 case LE_STR7('v','a','l','u','e','2','0'): {
10271 value_SetEnum(parent,atf_amc_FieldId_value20); ret = true; break;
10272 }
10273 case LE_STR7('v','a','l','u','e','2','1'): {
10274 value_SetEnum(parent,atf_amc_FieldId_value21); ret = true; break;
10275 }
10276 case LE_STR7('v','a','l','u','e','2','2'): {
10277 value_SetEnum(parent,atf_amc_FieldId_value22); ret = true; break;
10278 }
10279 case LE_STR7('v','a','l','u','e','2','3'): {
10280 value_SetEnum(parent,atf_amc_FieldId_value23); ret = true; break;
10281 }
10282 case LE_STR7('v','a','l','u','e','2','4'): {
10283 value_SetEnum(parent,atf_amc_FieldId_value24); ret = true; break;
10284 }
10285 case LE_STR7('v','a','l','u','e','2','5'): {
10286 value_SetEnum(parent,atf_amc_FieldId_value25); ret = true; break;
10287 }
10288 case LE_STR7('v','a','l','u','e','2','6'): {
10289 value_SetEnum(parent,atf_amc_FieldId_value26); ret = true; break;
10290 }
10291 case LE_STR7('v','a','l','u','e','2','7'): {
10292 value_SetEnum(parent,atf_amc_FieldId_value27); ret = true; break;
10293 }
10294 case LE_STR7('v','a','l','u','e','2','8'): {
10295 value_SetEnum(parent,atf_amc_FieldId_value28); ret = true; break;
10296 }
10297 case LE_STR7('v','a','l','u','e','2','9'): {
10298 value_SetEnum(parent,atf_amc_FieldId_value29); ret = true; break;
10299 }
10300 case LE_STR7('v','a','l','u','e','3','0'): {
10301 value_SetEnum(parent,atf_amc_FieldId_value30); ret = true; break;
10302 }
10303 case LE_STR7('v','a','l','u','e','3','1'): {
10304 value_SetEnum(parent,atf_amc_FieldId_value31); ret = true; break;
10305 }
10306 case LE_STR7('v','a','l','u','e','3','2'): {
10307 value_SetEnum(parent,atf_amc_FieldId_value32); ret = true; break;
10308 }
10309 case LE_STR7('v','a','l','u','e','3','3'): {
10310 value_SetEnum(parent,atf_amc_FieldId_value33); ret = true; break;
10311 }
10312 case LE_STR7('v','a','l','u','e','3','4'): {
10313 value_SetEnum(parent,atf_amc_FieldId_value34); ret = true; break;
10314 }
10315 case LE_STR7('v','a','l','u','e','3','5'): {
10316 value_SetEnum(parent,atf_amc_FieldId_value35); ret = true; break;
10317 }
10318 case LE_STR7('v','a','l','u','e','3','6'): {
10319 value_SetEnum(parent,atf_amc_FieldId_value36); ret = true; break;
10320 }
10321 case LE_STR7('v','a','l','u','e','3','7'): {
10322 value_SetEnum(parent,atf_amc_FieldId_value37); ret = true; break;
10323 }
10324 case LE_STR7('v','a','l','u','e','3','8'): {
10325 value_SetEnum(parent,atf_amc_FieldId_value38); ret = true; break;
10326 }
10327 case LE_STR7('v','a','l','u','e','3','9'): {
10328 value_SetEnum(parent,atf_amc_FieldId_value39); ret = true; break;
10329 }
10330 case LE_STR7('v','a','l','u','e','4','0'): {
10331 value_SetEnum(parent,atf_amc_FieldId_value40); ret = true; break;
10332 }
10333 case LE_STR7('v','a','l','u','e','4','1'): {
10334 value_SetEnum(parent,atf_amc_FieldId_value41); ret = true; break;
10335 }
10336 case LE_STR7('v','a','l','u','e','4','2'): {
10337 value_SetEnum(parent,atf_amc_FieldId_value42); ret = true; break;
10338 }
10339 case LE_STR7('v','a','l','u','e','4','3'): {
10340 value_SetEnum(parent,atf_amc_FieldId_value43); ret = true; break;
10341 }
10342 case LE_STR7('v','a','l','u','e','4','4'): {
10343 value_SetEnum(parent,atf_amc_FieldId_value44); ret = true; break;
10344 }
10345 case LE_STR7('v','a','l','u','e','4','5'): {
10346 value_SetEnum(parent,atf_amc_FieldId_value45); ret = true; break;
10347 }
10348 case LE_STR7('v','a','l','u','e','4','6'): {
10349 value_SetEnum(parent,atf_amc_FieldId_value46); ret = true; break;
10350 }
10351 case LE_STR7('v','a','l','u','e','4','7'): {
10352 value_SetEnum(parent,atf_amc_FieldId_value47); ret = true; break;
10353 }
10354 case LE_STR7('v','a','l','u','e','4','8'): {
10355 value_SetEnum(parent,atf_amc_FieldId_value48); ret = true; break;
10356 }
10357 case LE_STR7('v','a','l','u','e','4','9'): {
10358 value_SetEnum(parent,atf_amc_FieldId_value49); ret = true; break;
10359 }
10360 case LE_STR7('v','a','l','u','e','5','0'): {
10361 value_SetEnum(parent,atf_amc_FieldId_value50); ret = true; break;
10362 }
10363 case LE_STR7('v','a','l','u','e','5','1'): {
10364 value_SetEnum(parent,atf_amc_FieldId_value51); ret = true; break;
10365 }
10366 case LE_STR7('v','a','l','u','e','5','2'): {
10367 value_SetEnum(parent,atf_amc_FieldId_value52); ret = true; break;
10368 }
10369 case LE_STR7('v','a','l','u','e','5','3'): {
10370 value_SetEnum(parent,atf_amc_FieldId_value53); ret = true; break;
10371 }
10372 case LE_STR7('v','a','l','u','e','5','4'): {
10373 value_SetEnum(parent,atf_amc_FieldId_value54); ret = true; break;
10374 }
10375 case LE_STR7('v','a','l','u','e','5','5'): {
10376 value_SetEnum(parent,atf_amc_FieldId_value55); ret = true; break;
10377 }
10378 case LE_STR7('v','a','l','u','e','5','6'): {
10379 value_SetEnum(parent,atf_amc_FieldId_value56); ret = true; break;
10380 }
10381 case LE_STR7('v','a','l','u','e','5','7'): {
10382 value_SetEnum(parent,atf_amc_FieldId_value57); ret = true; break;
10383 }
10384 case LE_STR7('v','a','l','u','e','5','8'): {
10385 value_SetEnum(parent,atf_amc_FieldId_value58); ret = true; break;
10386 }
10387 case LE_STR7('v','a','l','u','e','5','9'): {
10388 value_SetEnum(parent,atf_amc_FieldId_value59); ret = true; break;
10389 }
10390 case LE_STR7('v','a','l','u','e','6','0'): {
10391 value_SetEnum(parent,atf_amc_FieldId_value60); ret = true; break;
10392 }
10393 case LE_STR7('v','a','l','u','e','6','1'): {
10394 value_SetEnum(parent,atf_amc_FieldId_value61); ret = true; break;
10395 }
10396 case LE_STR7('v','a','l','u','e','6','2'): {
10397 value_SetEnum(parent,atf_amc_FieldId_value62); ret = true; break;
10398 }
10399 case LE_STR7('v','a','l','u','e','6','3'): {
10400 value_SetEnum(parent,atf_amc_FieldId_value63); ret = true; break;
10401 }
10402 case LE_STR7('v','a','l','u','e','6','4'): {
10403 value_SetEnum(parent,atf_amc_FieldId_value64); ret = true; break;
10404 }
10405 case LE_STR7('v','a','l','u','e','6','5'): {
10406 value_SetEnum(parent,atf_amc_FieldId_value65); ret = true; break;
10407 }
10408 case LE_STR7('v','a','l','u','e','6','6'): {
10409 value_SetEnum(parent,atf_amc_FieldId_value66); ret = true; break;
10410 }
10411 case LE_STR7('v','a','l','u','e','6','7'): {
10412 value_SetEnum(parent,atf_amc_FieldId_value67); ret = true; break;
10413 }
10414 case LE_STR7('v','a','l','u','e','6','8'): {
10415 value_SetEnum(parent,atf_amc_FieldId_value68); ret = true; break;
10416 }
10417 case LE_STR7('v','a','l','u','e','6','9'): {
10418 value_SetEnum(parent,atf_amc_FieldId_value69); ret = true; break;
10419 }
10420 case LE_STR7('v','a','l','u','e','7','0'): {
10421 value_SetEnum(parent,atf_amc_FieldId_value70); ret = true; break;
10422 }
10423 case LE_STR7('v','a','l','u','e','7','1'): {
10424 value_SetEnum(parent,atf_amc_FieldId_value71); ret = true; break;
10425 }
10426 }
10427 break;
10428 }
10429 case 8: {
10430 switch (algo::ReadLE64(rhs.elems)) {
10431 case LE_STR8('a','s','s','i','g','n','e','d'): {
10432 value_SetEnum(parent,atf_amc_FieldId_assigned); ret = true; break;
10433 }
10434 case LE_STR8('f','r','e','e','b','o','o','l'): {
10435 value_SetEnum(parent,atf_amc_FieldId_freebool); ret = true; break;
10436 }
10437 case LE_STR8('n','u','l','l','a','b','l','e'): {
10438 value_SetEnum(parent,atf_amc_FieldId_nullable); ret = true; break;
10439 }
10440 }
10441 break;
10442 }
10443 case 10: {
10444 switch (algo::ReadLE64(rhs.elems)) {
10445 case LE_STR8('e','n','d','_','i','n','t','v'): {
10446 if (memcmp(rhs.elems+8,"al",2)==0) { value_SetEnum(parent,atf_amc_FieldId_end_intval); ret = true; break; }
10447 break;
10448 }
10449 }
10450 break;
10451 }
10452 case 11: {
10453 switch (algo::ReadLE64(rhs.elems)) {
10454 case LE_STR8('e','n','d','_','d','a','t','e'): {
10455 if (memcmp(rhs.elems+8,"val",3)==0) { value_SetEnum(parent,atf_amc_FieldId_end_dateval); ret = true; break; }
10456 break;
10457 }
10458 case LE_STR8('s','t','r','v','a','l','_','r'): {
10459 if (memcmp(rhs.elems+8,"egx",3)==0) { value_SetEnum(parent,atf_amc_FieldId_strval_regx); ret = true; break; }
10460 break;
10461 }
10462 }
10463 break;
10464 }
10465 case 12: {
10466 switch (algo::ReadLE64(rhs.elems)) {
10467 case LE_STR8('s','t','a','r','t','_','i','n'): {
10468 if (memcmp(rhs.elems+8,"tval",4)==0) { value_SetEnum(parent,atf_amc_FieldId_start_intval); ret = true; break; }
10469 break;
10470 }
10471 case LE_STR8('s','t','r','v','a','l','2','_'): {
10472 if (memcmp(rhs.elems+8,"regx",4)==0) { value_SetEnum(parent,atf_amc_FieldId_strval2_regx); ret = true; break; }
10473 break;
10474 }
10475 }
10476 break;
10477 }
10478 case 13: {
10479 switch (algo::ReadLE64(rhs.elems)) {
10480 case LE_STR8('s','t','a','r','t','_','d','a'): {
10481 if (memcmp(rhs.elems+8,"teval",5)==0) { value_SetEnum(parent,atf_amc_FieldId_start_dateval); ret = true; break; }
10482 break;
10483 }
10484 }
10485 break;
10486 }
10487 }
10488 return ret;
10489}
10490
10491// --- atf_amc.FieldId.value.SetStrptr
10492// Convert string to field.
10493// If the string is invalid, set numeric value to DFLT
10494void atf_amc::value_SetStrptr(atf_amc::FieldId& parent, algo::strptr rhs, atf_amc_FieldIdEnum dflt) {
10495 if (!value_SetStrptrMaybe(parent,rhs)) value_SetEnum(parent,dflt);
10496}
10497
10498// --- atf_amc.FieldId.value.ReadStrptrMaybe
10499// Convert string to field. Return success value
10500bool atf_amc::value_ReadStrptrMaybe(atf_amc::FieldId& parent, algo::strptr rhs) {
10501 bool retval = false;
10502 retval = value_SetStrptrMaybe(parent,rhs); // try symbol conversion
10503 if (!retval) { // didn't work? try reading as underlying type
10504 retval = i32_ReadStrptrMaybe(parent.value,rhs);
10505 }
10506 return retval;
10507}
10508
10509// --- atf_amc.FieldId..ReadStrptrMaybe
10510// Read fields of atf_amc::FieldId from an ascii string.
10511// The format of the string is the format of the atf_amc::FieldId's only field
10512bool atf_amc::FieldId_ReadStrptrMaybe(atf_amc::FieldId &parent, algo::strptr in_str) {
10513 bool retval = true;
10514 retval = retval && value_ReadStrptrMaybe(parent, in_str);
10515 return retval;
10516}
10517
10518// --- atf_amc.FieldId..Print
10519// print string representation of ROW to string STR
10520// cfmt:atf_amc.FieldId.String printfmt:Raw
10521void atf_amc::FieldId_Print(atf_amc::FieldId& row, algo::cstring& str) {
10522 atf_amc::value_Print(row, str);
10523}
10524
10525// --- atf_amc.InlaryPrint.fixary.Print
10526// Convert fixary to a string.
10527// The separator character is ' '.
10528void atf_amc::fixary_Print(atf_amc::InlaryPrint& parent, algo::cstring &rhs) {
10529 ind_beg(InlaryPrint_fixary_curs,fixary_elem,parent) {
10530 if (ind_curs(fixary_elem).index > 0) {
10531 rhs << ' ';
10532 }
10533 u32_Print(fixary_elem, rhs);
10534 }ind_end;
10535}
10536
10537// --- atf_amc.InlaryPrint.fixary.ReadStrptrMaybe
10538// Read array from string
10539// Convert string to field. Return success value
10540bool atf_amc::fixary_ReadStrptrMaybe(atf_amc::InlaryPrint& parent, algo::strptr in_str) {
10541 bool retval = true;
10542 for (int i=0; in_str != "" && i < 3; i++) {
10543 algo::strptr token;
10544 algo::NextSep(in_str, ' ', token);
10545 retval = u32_ReadStrptrMaybe(parent.fixary_elems[i], token);
10546 if (!retval) {
10547 break;
10548 }
10549 }
10550 return retval;
10551}
10552
10553// --- atf_amc.InlaryPrint.inlary.Alloc
10554// Allocate memory for new default row.
10555// If out of memory, process is killed.
10556u32& atf_amc::inlary_Alloc(atf_amc::InlaryPrint& parent) {
10557 u32* row = inlary_AllocMaybe(parent);
10558 if (UNLIKELY(row == NULL)) {
10559 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.InlaryPrint.inlary comment:'Alloc failed'");
10560 }
10561 return *row;
10562}
10563
10564// --- atf_amc.InlaryPrint.inlary.AllocMaybe
10565// Allocate memory for new element. If out of memory, return NULL.
10566u32* atf_amc::inlary_AllocMaybe(atf_amc::InlaryPrint& parent) {
10567 u32 *row = (u32*)inlary_AllocMem(parent);
10568 if (row) {
10569 new (row) u32; // call constructor
10570 }
10571 return row;
10572}
10573
10574// --- atf_amc.InlaryPrint.inlary.RemoveAll
10575// Destroy all elements of Inlary
10576void atf_amc::inlary_RemoveAll(atf_amc::InlaryPrint& parent) {
10577 parent.inlary_n = 0;
10578}
10579
10580// --- atf_amc.InlaryPrint.inlary.RemoveLast
10581// Delete last element of array. Do nothing if array is empty.
10582void atf_amc::inlary_RemoveLast(atf_amc::InlaryPrint& parent) {
10583 u64 n = parent.inlary_n;
10584 if (n > 0) {
10585 n -= 1;
10586 parent.inlary_n = n;
10587 }
10588}
10589
10590// --- atf_amc.InlaryPrint.inlary.Print
10591// Convert inlary to a string.
10592// The separator character is ' '.
10593void atf_amc::inlary_Print(atf_amc::InlaryPrint& parent, algo::cstring &rhs) {
10594 ind_beg(InlaryPrint_inlary_curs,inlary_elem,parent) {
10595 if (ind_curs(inlary_elem).index > 0) {
10596 rhs << ' ';
10597 }
10598 u32_Print(inlary_elem, rhs);
10599 }ind_end;
10600}
10601
10602// --- atf_amc.InlaryPrint.inlary.ReadStrptrMaybe
10603// Read array from string
10604// Convert string to field. Return success value
10605bool atf_amc::inlary_ReadStrptrMaybe(atf_amc::InlaryPrint& parent, algo::strptr in_str) {
10606 bool retval = true;
10607 inlary_RemoveAll(parent);
10608 for (int i=0; in_str != "" && i < 10; i++) {
10609 algo::strptr token;
10610 algo::NextSep(in_str, ' ', token);
10611 if (i >= 0) { // make room for new element...
10612 u32 &elem = inlary_Alloc(parent);
10613 (void)elem; // will succeed due to a previous check
10614 }
10615 retval = u32_ReadStrptrMaybe(reinterpret_cast<u32*>(parent.inlary_data)[i], token);
10616 if (!retval) {
10617 inlary_RemoveLast(parent);
10618 break;
10619 }
10620 }
10621 return retval;
10622}
10623
10624// --- atf_amc.InlaryPrint..ReadFieldMaybe
10625bool atf_amc::InlaryPrint_ReadFieldMaybe(atf_amc::InlaryPrint& parent, algo::strptr field, algo::strptr strval) {
10626 bool retval = true;
10627 atf_amc::FieldId field_id;
10628 (void)value_SetStrptrMaybe(field_id,algo::Pathcomp(field, ".LL"));
10629 switch(field_id) {
10630 case atf_amc_FieldId_fixary: {
10631 retval = fixary_ReadStrptrMaybe(parent, strval);
10632 break;
10633 }
10634 case atf_amc_FieldId_inlary: {
10635 retval = inlary_ReadStrptrMaybe(parent, strval);
10636 break;
10637 }
10638 default: break;
10639 }
10640 if (!retval) {
10641 algo_lib::AppendErrtext("attr",field);
10642 }
10643 return retval;
10644}
10645
10646// --- atf_amc.InlaryPrint..ReadStrptrMaybe
10647// Read fields of atf_amc::InlaryPrint from an ascii string.
10648// The format of the string is an ssim Tuple
10649bool atf_amc::InlaryPrint_ReadStrptrMaybe(atf_amc::InlaryPrint &parent, algo::strptr in_str) {
10650 bool retval = true;
10651 retval = algo::StripTypeTag(in_str, "atf_amc.InlaryPrint");
10652 ind_beg(algo::Attr_curs, attr, in_str) {
10653 retval = retval && InlaryPrint_ReadFieldMaybe(parent, attr.name, attr.value);
10654 }ind_end;
10655 return retval;
10656}
10657
10658// --- atf_amc.InlaryPrint..Init
10659// Set all fields to initial values.
10660void atf_amc::InlaryPrint_Init(atf_amc::InlaryPrint& parent) {
10661 for (int i = 0; i < 3; i++) {
10662 parent.fixary_elems[i] = 0;
10663 }
10664 parent.inlary_n = 0; // inlary: initialize count
10665}
10666
10667// --- atf_amc.InlaryPrint..Uninit
10668void atf_amc::InlaryPrint_Uninit(atf_amc::InlaryPrint& parent) {
10669 atf_amc::InlaryPrint &row = parent; (void)row;
10670
10671 // atf_amc.InlaryPrint.inlary.Uninit (Inlary) //
10672 inlary_RemoveAll(parent);
10673}
10674
10675// --- atf_amc.InlaryPrint..Print
10676// print string representation of ROW to string STR
10677// cfmt:atf_amc.InlaryPrint.String printfmt:Tuple
10678void atf_amc::InlaryPrint_Print(atf_amc::InlaryPrint& row, algo::cstring& str) {
10679 algo::tempstr temp;
10680 str << "atf_amc.InlaryPrint";
10681
10682 atf_amc::fixary_Print(row, temp);
10683 PrintAttrSpaceReset(str,"fixary", temp);
10684
10685 atf_amc::inlary_Print(row, temp);
10686 PrintAttrSpaceReset(str,"inlary", temp);
10687}
10688
10689// --- atf_amc.Lary32.lary.Alloc
10690// Allocate memory for new default row.
10691// If out of memory, process is killed.
10692u32& atf_amc::lary_Alloc(atf_amc::Lary32& parent) {
10693 u32* row = lary_AllocMaybe(parent);
10694 if (UNLIKELY(row == NULL)) {
10695 FatalErrorExit("atf_amc.out_of_mem field:atf_amc.Lary32.lary comment:'Alloc failed'");
10696 }
10697 return *row;
10698}
10699
10700// --- atf_amc.Lary32.lary.AllocMaybe
10701// Allocate memory for new element. If out of memory, return NULL.
10702u32* atf_amc::lary_AllocMaybe(atf_amc::Lary32& parent) {
10703 u32 *row = (u32*)lary_AllocMem(parent);
10704 if (row) {
10705 new (row) u32; // call constructor
10706 }
10707 return row;
10708}
10709
10710// --- atf_amc.Lary32.lary.AllocMem
10711// Allocate space for one element. If no memory available, return NULL.
10712void* atf_amc::lary_AllocMem(atf_amc::Lary32& parent) {
10713 u64 new_nelems = parent.lary_n+1;
10714 // compute level and index on level
10715 u64 bsr = algo::u64_BitScanReverse(new_nelems);
10716 u64 base = u64(1)<<bsr;
10717 u64 index = new_nelems-base;
10718 void *ret = NULL;
10719 // if level doesn't exist yet, create it
10720 u32* lev = NULL;
10721 if (bsr < 32) {
10722 lev = parent.lary_lary[bsr];
10723 if (!lev) {
10724 lev=(u32*)algo_lib::malloc_AllocMem(sizeof(u32) * (u64(1)<<bsr));
10725 parent.lary_lary[bsr] = lev;
10726 }
10727 }
10728 // allocate element from this level
10729 if (lev) {
10730 parent.lary_n = i32(new_nelems);
10731 ret = lev + index;
10732 }
10733 return ret;
10734}
10735
10736// --- atf_amc.Lary32.lary.RemoveAll
10737// Remove all elements from Lary
10738void atf_amc::lary_RemoveAll(atf_amc::Lary32& parent) {
10739 parent.lary_n = 0;
10740}
10741
10742// --- atf_amc.Lary32.lary.RemoveLast
10743// Delete last element of array. Do nothing if array is empty.
10744void atf_amc::lary_RemoveLast(atf_amc::Lary32& parent) {
10745 u64 n = parent.lary_n;
10746 if (n > 0) {
10747 n -= 1;
10748 parent.lary_n = i32(n);
10749 }
10750}
10751
10752// --- atf_amc.Lary32..Init
10753// Set all fields to initial values.
10754void atf_amc::Lary32_Init(atf_amc::Lary32& parent) {
10755 // initialize LAry lary (atf_amc.Lary32.lary)
10756 parent.lary_n = 0;
10757 memset(parent.lary_lary, 0, sizeof(parent.lary_lary)); // zero out all level pointers
10758 u32* lary_first = (u32*)algo_lib::malloc_AllocMem(sizeof(u32) * (u64(1)<<4));
10759 if (!lary_first) {
10760 FatalErrorExit("out of memory");
10761 }
10762 for (int i = 0; i < 4; i++) {
10763 parent.lary_lary[i] = lary_first;
10764 lary_first += 1ULL<<i;
10765 }
10766}
10767
10768// --- atf_amc.Lary32..Uninit
10769void atf_amc::Lary32_Uninit(atf_amc::Lary32& parent) {
10770 atf_amc::Lary32 &row = parent; (void)row;
10771
10772 // atf_amc.Lary32.lary.Uninit (Lary) //
10773 // destroy atf_amc.Lary32.lary
10774 // destroy all elements
10775 lary_RemoveAll(parent);
10776 // destroy all levels. stop when NULL level is found -- there is nothing beyond it
10777 algo_lib::malloc_FreeMem(parent.lary_lary[0],sizeof(u32) * (u64(1)<<4));
10778 for (u64 i = 4; i < 32 && parent.lary_lary[i]; i++) {
10779 algo_lib::malloc_FreeMem(parent.lary_lary[i],sizeof(u32) * (u64(1)<<i));
10780 }
10781}
10782
10783// --- atf_amc.Linebuf.in.GetMsg
10784// Detect incoming message in buffer and return it
10785// Look for valid message at current position in the buffer.
10786// If message is already there, return a pointer to it. Do not skip message (call SkipMsg to do that).
10787// If there is no message, read once from underlying file descriptor and try again.
10788// The message is found by looking for delimiter '\n'.
10789// The return value is an aryptr. If ret.elems is non-NULL, the message is valid (possibly empty).
10790// If ret.elems is NULL, no message can be extracted from buffer.
10791// The returned aryptr excludes the trailing deliminter.
10792// SkipMsg will skip both the line and the deliminter.
10793// A partial line at the end of input is NOT returned (TODO?)
10794//
10795algo::aryptr<char> atf_amc::in_GetMsg(atf_amc::Linebuf& linebuf) {
10796 algo::aryptr<char> ret;
10797 if (!linebuf.in_msgvalid) {
10798 in_Scanmsg(linebuf);
10799 }
10800 char *hdr = (char*)(linebuf.in_elems + linebuf.in_start);
10801 if (linebuf.in_msgvalid) {
10802 ret.elems = hdr;
10803 ret.n_elems = linebuf.in_msglen;
10804 }
10805 return ret;
10806}
10807
10808// --- atf_amc.Linebuf.in.RemoveAll
10809// Empty bfufer
10810// Discard contents of the buffer.
10811void atf_amc::in_RemoveAll(atf_amc::Linebuf& linebuf) {
10812 linebuf.in_start = 0;
10813 linebuf.in_end = 0;
10814 linebuf.in_msgvalid = false;
10815 linebuf.in_msglen = 0; // reset message length -- important for delimited streams
10816}
10817
10818// --- atf_amc.Linebuf.in.Scanmsg
10819// Internal function to scan for a message
10820//
10821static void atf_amc::in_Scanmsg(atf_amc::Linebuf& linebuf) {
10822 char *hdr = (char*)(linebuf.in_elems + linebuf.in_start);
10823 i32 avail = in_N(linebuf);
10824 i32 msglen;
10825 bool found = false;
10826 // scan for delimiter starting from the previous place where we left off.
10827 // at the end, save offset back to linebuf so we don't have to re-scan.
10828 // returned message length **does not include delimiter**.
10829 // a line that exceeds buffer length is not returned.
10830 for (msglen = linebuf.in_msglen; msglen < avail; msglen += sizeof(char)) {
10831 if (hdr[msglen] == '\n') { // delimiter?
10832 found = true;
10833 break;
10834 }
10835 }
10836 if (!found && msglen >= in_Max(linebuf)) {
10837 linebuf.in_eof = true; // cause user to detect eof
10838 linebuf.in_err = algo::FromErrno(E2BIG); // argument list too big -- closest error code
10839 }
10840 linebuf.in_msglen = msglen;
10841 linebuf.in_msgvalid = found;
10842}
10843
10844// --- atf_amc.Linebuf.in.Shift
10845// Internal function to shift data left
10846// Shift existing bytes over to the beginning of the buffer
10847static void atf_amc::in_Shift(atf_amc::Linebuf& linebuf) {
10848 i32 start = linebuf.in_start;
10849 i32 bytes_n = linebuf.in_end - start;
10850 if (bytes_n > 0) {
10851 memmove(linebuf.in_elems, linebuf.in_elems + start, bytes_n);
10852 }
10853 linebuf.in_end = bytes_n;
10854 linebuf.in_start = 0;
10855}
10856
10857// --- atf_amc.Linebuf.in.SkipBytes
10858// Skip N bytes when reading
10859// Mark some buffer contents as read.
10860//
10861void atf_amc::in_SkipBytes(atf_amc::Linebuf& linebuf, int n) {
10862 int avail = linebuf.in_end - linebuf.in_start;
10863 n = i32_Min(n,avail);
10864 linebuf.in_start += n;
10865}
10866
10867// --- atf_amc.Linebuf.in.SkipMsg
10868// Skip current message, if any
10869// Skip current message, if any.
10870void atf_amc::in_SkipMsg(atf_amc::Linebuf& linebuf) {
10871 if (linebuf.in_msgvalid) {
10872 int skip = linebuf.in_msglen;
10873 skip += ssizeof(char); // delimiter
10874 i32 start = linebuf.in_start;
10875 start += skip;
10876 linebuf.in_start = start;
10877 linebuf.in_msgvalid = false;
10878 linebuf.in_msglen = 0; // reset message length -- important for delimited streams
10879 }
10880}
10881
10882// --- atf_amc.Linebuf.in.WriteAll
10883// Attempt to write buffer contents to fd
10884// Write bytes to the buffer. If the entire block is written, return true,
10885// Otherwise return false.
10886// Bytes in the buffer are potentially shifted left to make room for the message.
10887//
10888bool atf_amc::in_WriteAll(atf_amc::Linebuf& linebuf, u8 *in, i32 in_n) {
10889 int max = in_Max(linebuf);
10890 // check if message doesn't fit. if so, shift bytes over.
10891 if (linebuf.in_end + in_n > max) {
10892 in_Shift(linebuf);
10893 }
10894 // now try to write the message.
10895 i32 end = linebuf.in_end;
10896 bool fits = end + in_n <= max;
10897 if (fits && in_n > 0) {
10898 memcpy(linebuf.in_elems + end, in, in_n);
10899 linebuf.in_end = end + in_n;
10900 }
10901 return fits;
10902}
10903
10904// --- atf_amc.Linebuf..Init
10905// Set all fields to initial values.
10906void atf_amc::Linebuf_Init(atf_amc::Linebuf& linebuf) {
10907 linebuf.in_end = 0; // in: initialize
10908 linebuf.in_start = 0; // in: initialize
10909 linebuf.in_eof = false; // in: initialize
10910 linebuf.in_msgvalid = false; // in: initialize
10911 linebuf.in_msglen = 0; // in: initialize
10912 linebuf.in_epoll_enable = true; // in: initialize
10913}
10914
10915// --- atf_amc.Linebuf..Print
10916// print string representation of ROW to string STR
10917// cfmt:atf_amc.Linebuf.String printfmt:Raw
10918void atf_amc::Linebuf_Print(atf_amc::Linebuf& row, algo::cstring& str) {
10919 (void)row;//only to avoid -Wunused-parameter
10920 (void)str;//only to avoid -Wunused-parameter
10921}
10922
10923// --- atf_amc.MsgHdrLT.type.ToCstr
10924// Convert numeric value of field to one of predefined string constants.
10925// If string is found, return a static C string. Otherwise, return NULL.
10926const char* atf_amc::type_ToCstr(const atf_amc::MsgHdrLT& o) {
10927 const char *ret = NULL;
10928 switch(type_GetEnum(o)) {
10929 case atf_amc_MsgHdrLT_type_atf_amc_MsgLTA: ret = "atf_amc.MsgLTA"; break;
10930 case atf_amc_MsgHdrLT_type_atf_amc_MsgLTB: ret = "atf_amc.MsgLTB"; break;
10931 case atf_amc_MsgHdrLT_type_atf_amc_MsgLTO: ret = "atf_amc.MsgLTO"; break;
10932 case atf_amc_MsgHdrLT_type_atf_amc_MsgLTV: ret = "atf_amc.MsgLTV"; break;
10933 }
10934 return ret;
10935}
10936
10937// --- atf_amc.MsgHdrLT.type.Print
10938// Convert type to a string. First, attempt conversion to a known string.
10939// If no string matches, print type as a numeric value.
10940void atf_amc::type_Print(const atf_amc::MsgHdrLT& o, algo::cstring &lhs) {
10941 const char *strval = type_ToCstr(o);
10942 if (strval) {
10943 lhs << strval;
10944 } else {
10945 lhs << o.type;
10946 }
10947}
10948
10949// --- atf_amc.MsgHdrLT.type.SetStrptrMaybe
10950// Convert string to field.
10951// If the string is invalid, do not modify field and return false.
10952// In case of success, return true
10953bool atf_amc::type_SetStrptrMaybe(atf_amc::MsgHdrLT& o, algo::strptr rhs) {
10954 bool ret = false;
10955 switch (elems_N(rhs)) {
10956 case 14: {
10957 switch (algo::ReadLE64(rhs.elems)) {
10958 case LE_STR8('a','t','f','_','a','m','c','.'): {
10959 if (memcmp(rhs.elems+8,"MsgLTA",6)==0) { type_SetEnum(o,atf_amc_MsgHdrLT_type_atf_amc_MsgLTA); ret = true; break; }
10960 if (memcmp(rhs.elems+8,"MsgLTB",6)==0) { type_SetEnum(o,atf_amc_MsgHdrLT_type_atf_amc_MsgLTB); ret = true; break; }
10961 if (memcmp(rhs.elems+8,"MsgLTO",6)==0) { type_SetEnum(o,atf_amc_MsgHdrLT_type_atf_amc_MsgLTO); ret = true; break; }
10962 if (memcmp(rhs.elems+8,"MsgLTV",6)==0) { type_SetEnum(o,atf_amc_MsgHdrLT_type_atf_amc_MsgLTV); ret = true; break; }
10963 break;
10964 }
10965 }
10966 break;
10967 }
10968 }
10969 return ret;
10970}
10971
10972// --- atf_amc.MsgHdrLT.type.SetStrptr
10973// Convert string to field.
10974// If the string is invalid, set numeric value to DFLT
10975void atf_amc::type_SetStrptr(atf_amc::MsgHdrLT& o, algo::strptr rhs, atf_amc_MsgHdrLT_type_Enum dflt) {
10976 if (!type_SetStrptrMaybe(o,rhs)) type_SetEnum(o,dflt);
10977}
10978
10979// --- atf_amc.MsgHdrLT.type.ReadStrptrMaybe
10980// Convert string to field. Return success value
10981bool atf_amc::type_ReadStrptrMaybe(atf_amc::MsgHdrLT& o, algo::strptr rhs) {
10982 bool retval = false;
10983 retval = type_SetStrptrMaybe(o,rhs); // try symbol conversion
10984 if (!retval) { // didn't work? try reading as underlying type
10985 retval = char_ReadStrptrMaybe(o.type,rhs);
10986 }
10987 return retval;
10988}
10989
10990// --- atf_amc.MsgHdrLT..ReadFieldMaybe
10991bool atf_amc::MsgHdrLT_ReadFieldMaybe(atf_amc::MsgHdrLT& parent, algo::strptr field, algo::strptr strval) {
10992 bool retval = true;
10993 atf_amc::FieldId field_id;
10994 (void)value_SetStrptrMaybe(field_id,field);
10995 switch(field_id) {
10996 case atf_amc_FieldId_len: {
10997 retval = false;
10998 break;
10999 }
11000 case atf_amc_FieldId_type: {
11001 retval = type_ReadStrptrMaybe(parent, strval);
11002 break;
11003 }
11004 default: break;
11005 }
11006 if (!retval) {
11007 algo_lib::AppendErrtext("attr",field);
11008 }
11009 return retval;
11010}
11011
11012// --- atf_amc.MsgHdrLT..ReadStrptrMaybe
11013// Read fields of atf_amc::MsgHdrLT from an ascii string.
11014// The format of the string is an ssim Tuple
11015bool atf_amc::MsgHdrLT_ReadStrptrMaybe(atf_amc::MsgHdrLT &parent, algo::strptr in_str) {
11016 bool retval = true;
11017 retval = algo::StripTypeTag(in_str, "atf_amc.MsgHdrLT");
11018 ind_beg(algo::Attr_curs, attr, in_str) {
11019 retval = retval && MsgHdrLT_ReadFieldMaybe(parent, attr.name, attr.value);
11020 }ind_end;
11021 return retval;
11022}
11023
11024// --- atf_amc.MsgHdrLT..Print
11025// print string representation of ROW to string STR
11026// cfmt:atf_amc.MsgHdrLT.String printfmt:Tuple
11027void atf_amc::MsgHdrLT_Print(atf_amc::MsgHdrLT& row, algo::cstring& str) {
11028 algo::tempstr temp;
11029 str << "atf_amc.MsgHdrLT";
11030 (void)row;//only to avoid -Wunused-parameter
11031}
11032
11033// --- atf_amc.MsgHdrLTMsgsCase.value.ToCstr
11034// Convert numeric value of field to one of predefined string constants.
11035// If string is found, return a static C string. Otherwise, return NULL.
11036const char* atf_amc::value_ToCstr(const atf_amc::MsgHdrLTMsgsCase& parent) {
11037 const char *ret = NULL;
11038 switch(value_GetEnum(parent)) {
11039 case atf_amc_MsgHdrLTMsgsCase_atf_amc_MsgLTA: ret = "atf_amc.MsgLTA"; break;
11040 case atf_amc_MsgHdrLTMsgsCase_atf_amc_MsgLTB: ret = "atf_amc.MsgLTB"; break;
11041 case atf_amc_MsgHdrLTMsgsCase_atf_amc_MsgLTO: ret = "atf_amc.MsgLTO"; break;
11042 case atf_amc_MsgHdrLTMsgsCase_atf_amc_MsgLTV: ret = "atf_amc.MsgLTV"; break;
11043 }
11044 return ret;
11045}
11046
11047// --- atf_amc.MsgHdrLTMsgsCase.value.Print
11048// Convert value to a string. First, attempt conversion to a known string.
11049// If no string matches, print value as a numeric value.
11050void atf_amc::value_Print(const atf_amc::MsgHdrLTMsgsCase& parent, algo::cstring &lhs) {
11051 const char *strval = value_ToCstr(parent);
11052 if (strval) {
11053 lhs << strval;
11054 } else {
11055 lhs << parent.value;
11056 }
11057}
11058
11059// --- atf_amc.MsgHdrLTMsgsCase.value.SetStrptrMaybe
11060// Convert string to field.
11061// If the string is invalid, do not modify field and return false.
11062// In case of success, return true
11063bool atf_amc::value_SetStrptrMaybe(atf_amc::MsgHdrLTMsgsCase& parent, algo::strptr rhs) {
11064 bool ret = false;
11065 switch (elems_N(rhs)) {
11066 case 14: {
11067 switch (algo::ReadLE64(rhs.elems)) {
11068 case LE_STR8('a','t','f','_','a','m','c','.'): {
11069 if (memcmp(rhs.elems+8,"MsgLTA",6)==0) { value_SetEnum(parent,atf_amc_MsgHdrLTMsgsCase_atf_amc_MsgLTA); ret = true; break; }
11070 if (memcmp(rhs.elems+8,"MsgLTB",6)==0) { value_SetEnum(parent,atf_amc_MsgHdrLTMsgsCase_atf_amc_MsgLTB); ret = true; break; }
11071 if (memcmp(rhs.elems+8,"MsgLTO",6)==0) { value_SetEnum(parent,atf_amc_MsgHdrLTMsgsCase_atf_amc_MsgLTO); ret = true; break; }
11072 if (memcmp(rhs.elems+8,"MsgLTV",6)==0) { value_SetEnum(parent,atf_amc_MsgHdrLTMsgsCase_atf_amc_MsgLTV); ret = true; break; }
11073 break;
11074 }
11075 }
11076 break;
11077 }
11078 }
11079 return ret;
11080}
11081
11082// --- atf_amc.MsgHdrLTMsgsCase.value.SetStrptr
11083// Convert string to field.
11084// If the string is invalid, set numeric value to DFLT
11085void atf_amc::value_SetStrptr(atf_amc::MsgHdrLTMsgsCase& parent, algo::strptr rhs, atf_amc_MsgHdrLTMsgsCaseEnum dflt) {
11086 if (!value_SetStrptrMaybe(parent,rhs)) value_SetEnum(parent,dflt);
11087}
11088
11089// --- atf_amc.MsgHdrLTMsgsCase.value.ReadStrptrMaybe
11090// Convert string to field. Return success value
11091bool atf_amc::value_ReadStrptrMaybe(atf_amc::MsgHdrLTMsgsCase& parent, algo::strptr rhs) {
11092 bool retval = false;
11093 retval = value_SetStrptrMaybe(parent,rhs); // try symbol conversion
11094 if (!retval) { // didn't work? try reading as underlying type
11095 retval = u32_ReadStrptrMaybe(parent.value,rhs);
11096 }
11097 return retval;
11098}
11099
11100// --- atf_amc.MsgHdrLTMsgsCase..ReadStrptrMaybe
11101// Read fields of atf_amc::MsgHdrLTMsgsCase from an ascii string.
11102// The format of the string is the format of the atf_amc::MsgHdrLTMsgsCase's only field
11103bool atf_amc::MsgHdrLTMsgsCase_ReadStrptrMaybe(atf_amc::MsgHdrLTMsgsCase &parent, algo::strptr in_str) {
11104 bool retval = true;
11105 retval = retval && value_ReadStrptrMaybe(parent, in_str);
11106 return retval;
11107}
11108
11109// --- atf_amc.MsgType.value.ToCstr
11110// Convert numeric value of field to one of predefined string constants.
11111// If string is found, return a static C string. Otherwise, return NULL.
11112const char* atf_amc::value_ToCstr(const atf_amc::MsgType& parent) {
11113 const char *ret = NULL;
11114 switch(value_GetEnum(parent)) {
11115 case atf_amc_MsgType_atf_amc_Seqmsg: ret = "atf_amc.Seqmsg"; break;
11116 case atf_amc_MsgType_atf_amc_Text : ret = "atf_amc.Text"; break;
11117 case atf_amc_MsgType_atf_amc_VarlenMsg: ret = "atf_amc.VarlenMsg"; break;
11118 }
11119 return ret;
11120}
11121
11122// --- atf_amc.MsgType.value.Print
11123// Convert value to a string. First, attempt conversion to a known string.
11124// If no string matches, print value as a numeric value.
11125void atf_amc::value_Print(const atf_amc::MsgType& parent, algo::cstring &lhs) {
11126 const char *strval = value_ToCstr(parent);
11127 if (strval) {
11128 lhs << strval;
11129 } else {
11130 lhs << parent.value;
11131 }
11132}
11133
11134// --- atf_amc.MsgType.value.SetStrptrMaybe
11135// Convert string to field.
11136// If the string is invalid, do not modify field and return false.
11137// In case of success, return true
11138bool atf_amc::value_SetStrptrMaybe(atf_amc::MsgType& parent, algo::strptr rhs) {
11139 bool ret = false;
11140 switch (elems_N(rhs)) {
11141 case 12: {
11142 switch (algo::ReadLE64(rhs.elems)) {
11143 case LE_STR8('a','t','f','_','a','m','c','.'): {
11144 if (memcmp(rhs.elems+8,"Text",4)==0) { value_SetEnum(parent,atf_amc_MsgType_atf_amc_Text); ret = true; break; }
11145 break;
11146 }
11147 }
11148 break;
11149 }
11150 case 14: {
11151 switch (algo::ReadLE64(rhs.elems)) {
11152 case LE_STR8('a','t','f','_','a','m','c','.'): {
11153 if (memcmp(rhs.elems+8,"Seqmsg",6)==0) { value_SetEnum(parent,atf_amc_MsgType_atf_amc_Seqmsg); ret = true; break; }
11154 break;
11155 }
11156 }
11157 break;
11158 }
11159 case 17: {
11160 switch (algo::ReadLE64(rhs.elems)) {
11161 case LE_STR8('a','t','f','_','a','m','c','.'): {
11162 if (memcmp(rhs.elems+8,"VarlenMsg",9)==0) { value_SetEnum(parent,atf_amc_MsgType_atf_amc_VarlenMsg); ret = true; break; }
11163 break;
11164 }
11165 }
11166 break;
11167 }
11168 }
11169 return ret;
11170}
11171
11172// --- atf_amc.MsgType.value.SetStrptr
11173// Convert string to field.
11174// If the string is invalid, set numeric value to DFLT
11175void atf_amc::value_SetStrptr(atf_amc::MsgType& parent, algo::strptr rhs, atf_amc_MsgTypeEnum dflt) {
11176 if (!value_SetStrptrMaybe(parent,rhs)) value_SetEnum(parent,dflt);
11177}
11178
11179// --- atf_amc.MsgType.value.ReadStrptrMaybe
11180// Convert string to field. Return success value
11181bool atf_amc::value_ReadStrptrMaybe(atf_amc::MsgType& parent, algo::strptr rhs) {
11182 bool retval = false;
11183 retval = value_SetStrptrMaybe(parent,rhs); // try symbol conversion
11184 if (!retval) { // didn't work? try reading as underlying type
11185 retval = u16_ReadStrptrMaybe(parent.value,rhs);
11186 }
11187 return retval;
11188}
11189
11190// --- atf_amc.MsgType..ReadStrptrMaybe
11191// Read fields of atf_amc::MsgType from an ascii string.
11192// The format of the string is the format of the atf_amc::MsgType's only field
11193bool atf_amc::MsgType_ReadStrptrMaybe(atf_amc::MsgType &parent, algo::strptr in_str) {
11194 bool retval = true;
11195 retval = retval && value_ReadStrptrMaybe(parent, in_str);
11196 return retval;
11197}
11198
11199// --- atf_amc.MsgType..Print
11200// print string representation of ROW to string STR
11201// cfmt:atf_amc.MsgType.String printfmt:Raw
11202void atf_amc::MsgType_Print(atf_amc::MsgType row, algo::cstring& str) {
11203 atf_amc::value_Print(row, str);
11204}
11205
11206// --- atf_amc.MsgLength..ReadStrptrMaybe
11207// Read fields of atf_amc::MsgLength from an ascii string.
11208// The format of the string is the format of the atf_amc::MsgLength's only field
11209bool atf_amc::MsgLength_ReadStrptrMaybe(atf_amc::MsgLength &parent, algo::strptr in_str) {
11210 bool retval = true;
11211 retval = retval && u16_ReadStrptrMaybe(parent.value, in_str);
11212 return retval;
11213}
11214
11215// --- atf_amc.MsgLength..Print
11216// print string representation of ROW to string STR
11217// cfmt:atf_amc.MsgLength.String printfmt:Raw
11218void atf_amc::MsgLength_Print(atf_amc::MsgLength row, algo::cstring& str) {
11219 u16_Print(row.value, str);
11220}
11221
11222// --- atf_amc.MsgHeader..ReadFieldMaybe
11223bool atf_amc::MsgHeader_ReadFieldMaybe(atf_amc::MsgHeader& parent, algo::strptr field, algo::strptr strval) {
11224 bool retval = true;
11225 atf_amc::FieldId field_id;
11226 (void)value_SetStrptrMaybe(field_id,field);
11227 switch(field_id) {
11228 case atf_amc_FieldId_type: {
11229 retval = false;
11230 break;
11231 }
11232 case atf_amc_FieldId_length: {
11233 retval = false;
11234 break;
11235 }
11236 default: break;
11237 }
11238 if (!retval) {
11239 algo_lib::AppendErrtext("attr",field);
11240 }
11241 (void)parent;//only to avoid -Wunused-parameter
11242 (void)strval;//only to avoid -Wunused-parameter
11243 return retval;
11244}
11245
11246// --- atf_amc.MsgHeader..ReadStrptrMaybe
11247// Read fields of atf_amc::MsgHeader from an ascii string.
11248// The format of the string is an ssim Tuple
11249bool atf_amc::MsgHeader_ReadStrptrMaybe(atf_amc::MsgHeader &parent, algo::strptr in_str) {
11250 bool retval = true;
11251 retval = algo::StripTypeTag(in_str, "atf_amc.MsgHeader");
11252 ind_beg(algo::Attr_curs, attr, in_str) {
11253 retval = retval && MsgHeader_ReadFieldMaybe(parent, attr.name, attr.value);
11254 }ind_end;
11255 return retval;
11256}
11257
11258// --- atf_amc.MsgHeader..Print
11259// print string representation of ROW to string STR
11260// cfmt:atf_amc.MsgHeader.String printfmt:Tuple
11261void atf_amc::MsgHeader_Print(atf_amc::MsgHeader& row, algo::cstring& str) {
11262 algo::tempstr temp;
11263 str << "atf_amc.MsgHeader";
11264 (void)row;//only to avoid -Wunused-parameter
11265}
11266
11267// --- atf_amc.MsgLTA.base.CopyOut
11268// Copy fields out of row
11269void atf_amc::parent_CopyOut(atf_amc::MsgLTA &row, atf_amc::MsgHdrLT &out) {
11270 // len: field value is computed
11271 // type: field value is computed
11272 (void)row;//only to avoid -Wunused-parameter
11273 (void)out;//only to avoid -Wunused-parameter
11274}
11275
11276// --- atf_amc.MsgLTA..ReadFieldMaybe
11277bool atf_amc::MsgLTA_ReadFieldMaybe(atf_amc::MsgLTA& parent, algo::strptr field, algo::strptr strval) {
11278 bool retval = true;
11279 atf_amc::FieldId field_id;
11280 (void)value_SetStrptrMaybe(field_id,field);
11281 switch(field_id) {
11282 case atf_amc_FieldId_base: {
11283 retval = false;
11284 break;
11285 }
11286 case atf_amc_FieldId_len: {
11287 retval = false;
11288 break;
11289 }
11290 case atf_amc_FieldId_type: {
11291 retval = false;
11292 break;
11293 }
11294 case atf_amc_FieldId_a: {
11295 retval = algo::RspaceStr4_ReadStrptrMaybe(parent.a, strval);
11296 break;
11297 }
11298 default: break;
11299 }
11300 if (!retval) {
11301 algo_lib::AppendErrtext("attr",field);
11302 }
11303 return retval;
11304}
11305
11306// --- atf_amc.MsgLTA..ReadStrptrMaybe
11307// Read fields of atf_amc::MsgLTA from an ascii string.
11308// The format of the string is an ssim Tuple
11309bool atf_amc::MsgLTA_ReadStrptrMaybe(atf_amc::MsgLTA &parent, algo::strptr in_str) {
11310 bool retval = true;
11311 retval = algo::StripTypeTag(in_str, "atf_amc.MsgLTA");
11312 ind_beg(algo::Attr_curs, attr, in_str) {
11313 retval = retval && MsgLTA_ReadFieldMaybe(parent, attr.name, attr.value);
11314 }ind_end;
11315 return retval;
11316}
11317
11318// --- atf_amc.MsgLTA..Print
11319// print string representation of ROW to string STR
11320// cfmt:atf_amc.MsgLTA.String printfmt:Tuple
11321void atf_amc::MsgLTA_Print(atf_amc::MsgLTA& row, algo::cstring& str) {
11322 algo::tempstr temp;
11323 str << "atf_amc.MsgLTA";
11324
11325 algo::RspaceStr4_Print(row.a, temp);
11326 PrintAttrSpaceReset(str,"a", temp);
11327}
11328
11329// --- atf_amc.MsgLTB.base.CopyOut
11330// Copy fields out of row
11331void atf_amc::parent_CopyOut(atf_amc::MsgLTB &row, atf_amc::MsgHdrLT &out) {
11332 // len: field value is computed
11333 // type: field value is computed
11334 (void)row;//only to avoid -Wunused-parameter
11335 (void)out;//only to avoid -Wunused-parameter
11336}
11337
11338// --- atf_amc.MsgLTB..ReadFieldMaybe
11339bool atf_amc::MsgLTB_ReadFieldMaybe(atf_amc::MsgLTB& parent, algo::strptr field, algo::strptr strval) {
11340 bool retval = true;
11341 atf_amc::FieldId field_id;
11342 (void)value_SetStrptrMaybe(field_id,field);
11343 switch(field_id) {
11344 case atf_amc_FieldId_base: {
11345 retval = false;
11346 break;
11347 }
11348 case atf_amc_FieldId_len: {
11349 retval = false;
11350 break;
11351 }
11352 case atf_amc_FieldId_type: {
11353 retval = false;
11354 break;
11355 }
11356 case atf_amc_FieldId_b: {
11357 retval = algo::RspaceStr6_ReadStrptrMaybe(parent.b, strval);
11358 break;
11359 }
11360 default: break;
11361 }
11362 if (!retval) {
11363 algo_lib::AppendErrtext("attr",field);
11364 }
11365 return retval;
11366}
11367
11368// --- atf_amc.MsgLTB..ReadStrptrMaybe
11369// Read fields of atf_amc::MsgLTB from an ascii string.
11370// The format of the string is an ssim Tuple
11371bool atf_amc::MsgLTB_ReadStrptrMaybe(atf_amc::MsgLTB &parent, algo::strptr in_str) {
11372 bool retval = true;
11373 retval = algo::StripTypeTag(in_str, "atf_amc.MsgLTB");
11374 ind_beg(algo::Attr_curs, attr, in_str) {
11375 retval = retval && MsgLTB_ReadFieldMaybe(parent, attr.name, attr.value);
11376 }ind_end;
11377 return retval;
11378}
11379
11380// --- atf_amc.MsgLTB..Print
11381// print string representation of ROW to string STR
11382// cfmt:atf_amc.MsgLTB.String printfmt:Tuple
11383void atf_amc::MsgLTB_Print(atf_amc::MsgLTB& row, algo::cstring& str) {
11384 algo::tempstr temp;
11385 str << "atf_amc.MsgLTB";
11386
11387 algo::RspaceStr6_Print(row.b, temp);
11388 PrintAttrSpaceReset(str,"b", temp);
11389}
11390
11391// --- atf_amc.MsgLTO.base.CopyOut
11392// Copy fields out of row
11393void atf_amc::parent_CopyOut(atf_amc::MsgLTO &row, atf_amc::MsgHdrLT &out) {
11394 // len: field value is computed
11395 // type: field value is computed
11396 (void)row;//only to avoid -Wunused-parameter
11397 (void)out;//only to avoid -Wunused-parameter
11398}
11399
11400// --- atf_amc.MsgLTO.o.Getary
11401// Access optional portion as an array of bytes
11402algo::aryptr<u8> atf_amc::o_Getary(atf_amc::MsgLTO& parent) {
11403 u8 *end = (u8*)&parent + sizeof(atf_amc::MsgLTO);
11404 return algo::aryptr<u8>(end, i32(parent.len + 2) - ssizeof(atf_amc::MsgLTO));
11405}
11406
11407// --- atf_amc.MsgLTO.o.Print
11408void atf_amc::o_Print(atf_amc::MsgLTO& parent, cstring &out) {
11409 (void)out;
11410 (void)parent;
11411 if (atf_amc::MsgHdrLT *o = o_Get(parent)) {
11412 atf_amc::MsgHdrLTMsgs_Print(out, *o, INT_MAX);
11413 }
11414}
11415
11416// --- atf_amc.MsgLTO.o.ReadStrptrMaybe
11417// Convert string to field. Return success value
11418bool atf_amc::o_ReadStrptrMaybe(atf_amc::MsgLTO &parent, algo::strptr in_str) {
11419 bool retval = false;
11420 if (algo_lib::_db.varlenbuf) {
11421 algo::ByteAry temp;
11422 retval = atf_amc::MsgHdrLTMsgs_ReadStrptrMaybe(in_str, temp); // read any of several message types here
11423 ary_Setary(*algo_lib::_db.varlenbuf, ary_Getary(temp)); // return it
11424 }
11425 (void)parent;//only to avoid -Wunused-parameter
11426 return retval;
11427}
11428
11429// --- atf_amc.MsgLTO.o.XrefMaybe
11430// Insert row into all appropriate indices. If error occurs, store error
11431// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
11432bool atf_amc::o_XrefMaybe(atf_amc::MsgHdrLT &row) {
11433 bool retval = true;
11434 (void)row;
11435 return retval;
11436}
11437
11438// --- atf_amc.MsgLTO..ReadFieldMaybe
11439bool atf_amc::MsgLTO_ReadFieldMaybe(atf_amc::MsgLTO& parent, algo::strptr field, algo::strptr strval) {
11440 bool retval = true;
11441 atf_amc::FieldId field_id;
11442 (void)value_SetStrptrMaybe(field_id,field);
11443 switch(field_id) {
11444 case atf_amc_FieldId_base: {
11445 retval = false;
11446 break;
11447 }
11448 case atf_amc_FieldId_len: {
11449 retval = false;
11450 break;
11451 }
11452 case atf_amc_FieldId_type: {
11453 retval = false;
11454 break;
11455 }
11456 case atf_amc_FieldId_o: {
11457 retval = o_ReadStrptrMaybe(parent, strval);
11458 break;
11459 }
11460 default: break;
11461 }
11462 if (!retval) {
11463 algo_lib::AppendErrtext("attr",field);
11464 }
11465 return retval;
11466}
11467
11468// --- atf_amc.MsgLTO..ReadStrptrMaybe
11469// Any varlen fields are returned in algo_lib::_db.varlenbuf if set
11470// Read fields of atf_amc::MsgLTO from an ascii string.
11471// The format of the string is an ssim Tuple
11472bool atf_amc::MsgLTO_ReadStrptrMaybe(atf_amc::MsgLTO &parent, algo::strptr in_str) {
11473 bool retval = true;
11474 retval = algo::StripTypeTag(in_str, "atf_amc.MsgLTO");
11475 ind_beg(algo::Attr_curs, attr, in_str) {
11476 retval = retval && MsgLTO_ReadFieldMaybe(parent, attr.name, attr.value);
11477 }ind_end;
11478 return retval;
11479}
11480
11481// --- atf_amc.MsgLTO..Print
11482// print string representation of ROW to string STR
11483// cfmt:atf_amc.MsgLTO.String printfmt:Tuple
11484void atf_amc::MsgLTO_Print(atf_amc::MsgLTO& row, algo::cstring& str) {
11485 algo::tempstr temp;
11486 str << "atf_amc.MsgLTO";
11487
11488 if (o_Get(row)) {
11489 atf_amc::o_Print(row, temp);
11490 PrintAttrSpaceReset(str,"o", temp);
11491 }
11492}
11493
11494// --- atf_amc.MsgLTV.base.CopyOut
11495// Copy fields out of row
11496void atf_amc::parent_CopyOut(atf_amc::MsgLTV &row, atf_amc::MsgHdrLT &out) {
11497 // len: field value is computed
11498 // type: field value is computed
11499 (void)row;//only to avoid -Wunused-parameter
11500 (void)out;//only to avoid -Wunused-parameter
11501}
11502
11503// --- atf_amc.MsgLTV.v.Getary
11504// Access var-length portion as an aryptr. Length is determined from one of the fields.
11505algo::aryptr<u8> atf_amc::v_Getary(atf_amc::MsgLTV& parent) {
11506 return algo::aryptr<u8>(v_Addr(parent), v_N(parent));
11507}
11508
11509// --- atf_amc.MsgLTV.v.Addr
11510u8* atf_amc::v_Addr(atf_amc::MsgLTV& parent) {
11511 return (u8*)((u8*)&parent + sizeof(atf_amc::MsgLTV)); // address of varlen portion
11512}
11513
11514// --- atf_amc.MsgLTV.v.ReadStrptrMaybe
11515// Convert string to field. Return success value
11516bool atf_amc::v_ReadStrptrMaybe(atf_amc::MsgLTV& parent, algo::strptr in_str) {
11517 bool retval = true;
11518 if (algo_lib::_db.varlenbuf) {
11519 algo::ByteAry temp;
11520 retval = atf_amc::MsgHdrLTMsgs_ReadStrptrMaybe(in_str, temp); // read any of several message types here
11521 ary_Addary(*algo_lib::_db.varlenbuf, ary_Getary(temp)); // return it
11522 }
11523 (void)parent;//only to avoid -Wunused-parameter
11524 return retval;
11525}
11526
11527// --- atf_amc.MsgLTV..ReadFieldMaybe
11528bool atf_amc::MsgLTV_ReadFieldMaybe(atf_amc::MsgLTV& parent, algo::strptr field, algo::strptr strval) {
11529 bool retval = true;
11530 atf_amc::FieldId field_id;
11531 (void)value_SetStrptrMaybe(field_id,algo::Pathcomp(field, ".LL"));
11532 switch(field_id) {
11533 case atf_amc_FieldId_base: {
11534 retval = false;
11535 break;
11536 }
11537 case atf_amc_FieldId_len: {
11538 retval = false;
11539 break;
11540 }
11541 case atf_amc_FieldId_type: {
11542 retval = false;
11543 break;
11544 }
11545 case atf_amc_FieldId_v: {
11546 retval = v_ReadStrptrMaybe(parent, strval);
11547 break;
11548 }
11549 default: break;
11550 }
11551 if (!retval) {
11552 algo_lib::AppendErrtext("attr",field);
11553 }
11554 return retval;
11555}
11556
11557// --- atf_amc.MsgLTV..ReadStrptrMaybe
11558// Any varlen fields are returned in algo_lib::_db.varlenbuf if set
11559// Read fields of atf_amc::MsgLTV from an ascii string.
11560// The format of the string is an ssim Tuple
11561bool atf_amc::MsgLTV_ReadStrptrMaybe(atf_amc::MsgLTV &parent, algo::strptr in_str) {
11562 bool retval = true;
11563 retval = algo::StripTypeTag(in_str, "atf_amc.MsgLTV");
11564 ind_beg(algo::Attr_curs, attr, in_str) {
11565 retval = retval && MsgLTV_ReadFieldMaybe(parent, attr.name, attr.value);
11566 }ind_end;
11567 return retval;
11568}
11569
11570// --- atf_amc.MsgLTV..Print
11571// print string representation of ROW to string STR
11572// cfmt:atf_amc.MsgLTV.String printfmt:Tuple
11573void atf_amc::MsgLTV_Print(atf_amc::MsgLTV& row, algo::cstring& str) {
11574 algo::tempstr temp;
11575 str << "atf_amc.MsgLTV";
11576
11577 ind_beg(MsgLTV_v_curs,v,row) {
11578 atf_amc::MsgHdrLTMsgs_Print(temp, v, INT_MAX);
11579 tempstr name;
11580 name << "v.";
11581 name << ind_curs(v).index;
11582 PrintAttrSpaceReset(str, name, temp);
11583 }ind_end;
11584}
11585
11586// --- atf_amc.Msgbuf.in.BeginRead
11587// Attach fbuf to Iohook for reading
11588// Attach file descriptor and begin reading using edge-triggered epoll.
11589// File descriptor becomes owned by atf_amc::Msgbuf.in via FIohook field.
11590// Whenever the file descriptor becomes readable, insert msgbuf into cd_in_msg.
11591void atf_amc::in_BeginRead(atf_amc::Msgbuf& msgbuf, algo::Fildes fd) {
11592 callback_Set1(msgbuf.in_iohook, msgbuf, atf_amc::cd_in_msg_Insert);
11593 msgbuf.in_iohook.fildes = fd;
11594 IOEvtFlags flags;
11595 read_Set(flags, true);
11596 if (msgbuf.in_epoll_enable) {
11597 algo_lib::IohookAdd(msgbuf.in_iohook, flags);
11598 } else {
11599 atf_amc::cd_in_msg_Insert(msgbuf);
11600 }
11601}
11602
11603// --- atf_amc.Msgbuf.in.EndRead
11604// Set EOF flag
11605void atf_amc::in_EndRead(atf_amc::Msgbuf& msgbuf) {
11606 if (ValidQ(msgbuf.in_iohook.fildes)) {
11607 msgbuf.in_eof = true;
11608 atf_amc::cd_in_msg_Insert(msgbuf);
11609 }
11610}
11611
11612// --- atf_amc.Msgbuf.in.GetMsg
11613// Detect incoming message in buffer and return it
11614// Look for valid message at current position in the buffer.
11615// If message is already there, return a pointer to it. Do not skip message (call SkipMsg to do that).
11616// If there is no message, read once from underlying file descriptor and try again.
11617// The message is length-delimited based on field length field
11618//
11619atf_amc::MsgHeader* atf_amc::in_GetMsg(atf_amc::Msgbuf& msgbuf) {
11620 atf_amc::MsgHeader* ret;
11621 if (!msgbuf.in_msgvalid) {
11622 in_Scanmsg(msgbuf);
11623 if (!msgbuf.in_msgvalid) {
11624 bool readable = in_Refill(msgbuf);
11625 if (readable) {
11626 in_Scanmsg(msgbuf);
11627 }
11628 }
11629 }
11630 atf_amc::MsgHeader *hdr = (atf_amc::MsgHeader*)(msgbuf.in_elems + msgbuf.in_start);
11631 ret = msgbuf.in_msgvalid ? hdr : NULL;
11632 return ret;
11633}
11634
11635// --- atf_amc.Msgbuf.in.Refill
11636// Refill buffer. Return false if no further refill possible (input buffer exhausted)
11637bool atf_amc::in_Refill(atf_amc::Msgbuf& msgbuf) {
11638 bool readable = ValidQ(msgbuf.in_iohook.fildes);
11639 if (readable) {
11640 int fd = msgbuf.in_iohook.fildes.value;
11641 i32 max = in_Max(msgbuf);
11642 i32 end = msgbuf.in_end;
11643 i32 nbytes = end - msgbuf.in_start; // # bytes currently in buffer
11644 i32 nfree = max - end; // bytes available at the end of buffer
11645 if (nbytes == 0 || nfree == 0) { // make more room for reading (or take advantage of free shift)
11646 in_Shift(msgbuf);
11647 end = msgbuf.in_end;
11648 nfree = max - end;
11649 }
11650 ssize_t ret = read(fd, msgbuf.in_elems + end, nfree);
11651 readable = !(ret < 0 && errno == EAGAIN);
11652 bool error = ret < 0 && errno != EAGAIN; // detect permanent error on this fd
11653 bool eof = error || (ret == 0 && nfree > 0);
11654 msgbuf.in_end += i32_Max(ret,0); // new end of bytes
11655 if (error) {
11656 msgbuf.in_err = algo::FromErrno(errno); // fetch errno
11657 }
11658 msgbuf.in_eof |= eof;
11659 }
11660 if (!readable && msgbuf.in_epoll_enable) {
11661 atf_amc::cd_in_msg_Remove(msgbuf);
11662 }
11663 return readable;
11664}
11665
11666// --- atf_amc.Msgbuf.in.RemoveAll
11667// Empty bfufer
11668// Discard contents of the buffer.
11669void atf_amc::in_RemoveAll(atf_amc::Msgbuf& msgbuf) {
11670 msgbuf.in_start = 0;
11671 msgbuf.in_end = 0;
11672 msgbuf.in_msgvalid = false;
11673 msgbuf.in_msglen = 0; // reset message length -- important for delimited streams
11674}
11675
11676// --- atf_amc.Msgbuf.in.Scanmsg
11677// Internal function to scan for a message
11678//
11679static void atf_amc::in_Scanmsg(atf_amc::Msgbuf& msgbuf) {
11680 atf_amc::MsgHeader *hdr = (atf_amc::MsgHeader*)(msgbuf.in_elems + msgbuf.in_start);
11681 i32 avail = in_N(msgbuf);
11682 i32 msglen;
11683 bool found = false;
11684 msglen = ssizeof(atf_amc::MsgHeader);
11685 if (avail >= msglen) {
11686 msglen = i32((*hdr).length); // check rest of the message
11687 }
11688 found = msglen >= ssizeof(atf_amc::MsgHeader) && avail >= msglen;
11689 if (msglen < ssizeof(atf_amc::MsgHeader) || msglen > in_Max(msgbuf)) {
11690 msgbuf.in_eof = true; // cause user to detect eof
11691 msgbuf.in_err = algo::FromErrno(E2BIG); // argument list too big -- closest error code
11692 }
11693 msgbuf.in_msglen = msglen;
11694 msgbuf.in_msgvalid = found;
11695}
11696
11697// --- atf_amc.Msgbuf.in.Shift
11698// Internal function to shift data left
11699// Shift existing bytes over to the beginning of the buffer
11700static void atf_amc::in_Shift(atf_amc::Msgbuf& msgbuf) {
11701 i32 start = msgbuf.in_start;
11702 i32 bytes_n = msgbuf.in_end - start;
11703 if (bytes_n > 0) {
11704 memmove(msgbuf.in_elems, msgbuf.in_elems + start, bytes_n);
11705 }
11706 msgbuf.in_end = bytes_n;
11707 msgbuf.in_start = 0;
11708}
11709
11710// --- atf_amc.Msgbuf.in.SkipMsg
11711// Skip current message, if any
11712// Skip current message, if any.
11713void atf_amc::in_SkipMsg(atf_amc::Msgbuf& msgbuf) {
11714 if (msgbuf.in_msgvalid) {
11715 int skip = msgbuf.in_msglen;
11716 i32 start = msgbuf.in_start;
11717 start += skip;
11718 msgbuf.in_start = start;
11719 msgbuf.in_msgvalid = false;
11720 msgbuf.in_msglen = 0; // reset message length -- important for delimited streams
11721 }
11722}
11723
11724// --- atf_amc.Msgbuf.in.WriteAll
11725// Attempt to write buffer contents to fd
11726// Write bytes to the buffer. If the entire block is written, return true,
11727// Otherwise return false.
11728// Bytes in the buffer are potentially shifted left to make room for the message.
11729//
11730bool atf_amc::in_WriteAll(atf_amc::Msgbuf& msgbuf, u8 *in, i32 in_n) {
11731 int max = in_Max(msgbuf);
11732 // check if message doesn't fit. if so, shift bytes over.
11733 if (msgbuf.in_end + in_n > max) {
11734 in_Shift(msgbuf);
11735 }
11736 // now try to write the message.
11737 i32 end = msgbuf.in_end;
11738 bool fits = end + in_n <= max;
11739 if (fits && in_n > 0) {
11740 memcpy(msgbuf.in_elems + end, in, in_n);
11741 msgbuf.in_end = end + in_n;
11742 }
11743 return fits;
11744}
11745
11746// --- atf_amc.Msgbuf.in.XrefMaybe
11747// Insert row into all appropriate indices. If error occurs, store error
11748// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
11749bool atf_amc::in_XrefMaybe(atf_amc::MsgHeader &row) {
11750 bool retval = true;
11751 (void)row;
11752 return retval;
11753}
11754
11755// --- atf_amc.Msgbuf.out_extra.RemoveAll
11756// Empty bfufer
11757// Discard contents of the buffer.
11758void atf_amc::out_extra_RemoveAll(atf_amc::Msgbuf& msgbuf) {
11759 msgbuf.out_extra_start = 0;
11760 msgbuf.out_extra_end = 0;
11761}
11762
11763// --- atf_amc.Msgbuf.out_extra.Shift
11764// Internal function to shift data left
11765// Shift existing bytes over to the beginning of the buffer
11766static void atf_amc::out_extra_Shift(atf_amc::Msgbuf& msgbuf) {
11767 i32 start = msgbuf.out_extra_start;
11768 i32 bytes_n = msgbuf.out_extra_end - start;
11769 if (bytes_n > 0) {
11770 memmove(msgbuf.out_extra_elems, msgbuf.out_extra_elems + start, bytes_n);
11771 }
11772 msgbuf.out_extra_end = bytes_n;
11773 msgbuf.out_extra_start = 0;
11774}
11775
11776// --- atf_amc.Msgbuf.out_extra.SkipBytes
11777// Skip N bytes when reading
11778// Mark some buffer contents as read.
11779//
11780void atf_amc::out_extra_SkipBytes(atf_amc::Msgbuf& msgbuf, int n) {
11781 int avail = msgbuf.out_extra_end - msgbuf.out_extra_start;
11782 n = i32_Min(n,avail);
11783 msgbuf.out_extra_start += n;
11784}
11785
11786// --- atf_amc.Msgbuf.out_extra.WriteAll
11787// Attempt to write buffer contents to fd
11788// Write bytes to the buffer. If the entire block is written, return true,
11789// Otherwise return false.
11790// Bytes in the buffer are potentially shifted left to make room for the message.
11791//
11792bool atf_amc::out_extra_WriteAll(atf_amc::Msgbuf& msgbuf, u8 *in, i32 in_n) {
11793 int max = out_extra_Max(msgbuf);
11794 // check if message doesn't fit. if so, shift bytes over.
11795 if (msgbuf.out_extra_end + in_n > max) {
11796 out_extra_Shift(msgbuf);
11797 }
11798 // now try to write the message.
11799 i32 end = msgbuf.out_extra_end;
11800 bool fits = end + in_n <= max;
11801 if (fits && in_n > 0) {
11802 memcpy(msgbuf.out_extra_elems + end, in, in_n);
11803 msgbuf.out_extra_end = end + in_n;
11804 }
11805 return fits;
11806}
11807
11808// --- atf_amc.Msgbuf.out_extra.WriteMsg
11809// Write message to buffer. If the entire message is written, return true, otherwise false.
11810bool atf_amc::out_extra_WriteMsg(atf_amc::Msgbuf& msgbuf, atf_amc::MsgHdrLT &msg) {
11811 return out_extra_WriteAll(msgbuf, (u8*)&msg, i32(msg.len + 2));
11812}
11813
11814// --- atf_amc.Msgbuf.in_extra.GetMsg
11815// Detect incoming message in buffer and return it
11816// Look for valid message at current position in the buffer.
11817// If message is already there, return a pointer to it. Do not skip message (call SkipMsg to do that).
11818// If there is no message, read once from underlying file descriptor and try again.
11819// The message is length-delimited based on field len field
11820//
11821atf_amc::MsgHdrLT* atf_amc::in_extra_GetMsg(atf_amc::Msgbuf& msgbuf) {
11822 atf_amc::MsgHdrLT* ret;
11823 if (!msgbuf.in_extra_msgvalid) {
11824 in_extra_Scanmsg(msgbuf);
11825 }
11826 atf_amc::MsgHdrLT *hdr = (atf_amc::MsgHdrLT*)(msgbuf.in_extra_elems + msgbuf.in_extra_start);
11827 ret = msgbuf.in_extra_msgvalid ? hdr : NULL;
11828 return ret;
11829}
11830
11831// --- atf_amc.Msgbuf.in_extra.RemoveAll
11832// Empty bfufer
11833// Discard contents of the buffer.
11834void atf_amc::in_extra_RemoveAll(atf_amc::Msgbuf& msgbuf) {
11835 msgbuf.in_extra_start = 0;
11836 msgbuf.in_extra_end = 0;
11837 msgbuf.in_extra_msgvalid = false;
11838 msgbuf.in_extra_msglen = 0; // reset message length -- important for delimited streams
11839}
11840
11841// --- atf_amc.Msgbuf.in_extra.Scanmsg
11842// Internal function to scan for a message
11843//
11844static void atf_amc::in_extra_Scanmsg(atf_amc::Msgbuf& msgbuf) {
11845 atf_amc::MsgHdrLT *hdr = (atf_amc::MsgHdrLT*)(msgbuf.in_extra_elems + msgbuf.in_extra_start);
11846 i32 avail = in_extra_N(msgbuf);
11847 i32 msglen;
11848 bool found = false;
11849 msglen = ssizeof(atf_amc::MsgHdrLT);
11850 if (avail >= msglen) {
11851 msglen = i32((*hdr).len + 2); // check rest of the message
11852 }
11853 found = msglen >= ssizeof(atf_amc::MsgHdrLT) && avail >= msglen;
11854 if (msglen < ssizeof(atf_amc::MsgHdrLT) || msglen > in_extra_Max(msgbuf)) {
11855 msgbuf.in_extra_eof = true; // cause user to detect eof
11856 msgbuf.in_extra_err = algo::FromErrno(E2BIG); // argument list too big -- closest error code
11857 }
11858 msgbuf.in_extra_msglen = msglen;
11859 msgbuf.in_extra_msgvalid = found;
11860}
11861
11862// --- atf_amc.Msgbuf.in_extra.Shift
11863// Internal function to shift data left
11864// Shift existing bytes over to the beginning of the buffer
11865static void atf_amc::in_extra_Shift(atf_amc::Msgbuf& msgbuf) {
11866 i32 start = msgbuf.in_extra_start;
11867 i32 bytes_n = msgbuf.in_extra_end - start;
11868 if (bytes_n > 0) {
11869 memmove(msgbuf.in_extra_elems, msgbuf.in_extra_elems + start, bytes_n);
11870 }
11871 msgbuf.in_extra_end = bytes_n;
11872 msgbuf.in_extra_start = 0;
11873}
11874
11875// --- atf_amc.Msgbuf.in_extra.SkipMsg
11876// Skip current message, if any
11877// Skip current message, if any.
11878void atf_amc::in_extra_SkipMsg(atf_amc::Msgbuf& msgbuf) {
11879 if (msgbuf.in_extra_msgvalid) {
11880 int skip = msgbuf.in_extra_msglen;
11881 i32 start = msgbuf.in_extra_start;
11882 start += skip;
11883 msgbuf.in_extra_start = start;
11884 msgbuf.in_extra_msgvalid = false;
11885 msgbuf.in_extra_msglen = 0; // reset message length -- important for delimited streams
11886 }
11887}
11888
11889// --- atf_amc.Msgbuf.in_extra.WriteAll
11890// Attempt to write buffer contents to fd
11891// Write bytes to the buffer. If the entire block is written, return true,
11892// Otherwise return false.
11893// Bytes in the buffer are potentially shifted left to make room for the message.
11894//
11895bool atf_amc::in_extra_WriteAll(atf_amc::Msgbuf& msgbuf, u8 *in, i32 in_n) {
11896 int max = in_extra_Max(msgbuf);
11897 // check if message doesn't fit. if so, shift bytes over.
11898 if (msgbuf.in_extra_end + in_n > max) {
11899 in_extra_Shift(msgbuf);
11900 }
11901 // now try to write the message.
11902 i32 end = msgbuf.in_extra_end;
11903 bool fits = end + in_n <= max;
11904 if (fits && in_n > 0) {
11905 memcpy(msgbuf.in_extra_elems + end, in, in_n);
11906 msgbuf.in_extra_end = end + in_n;
11907 }
11908 return fits;
11909}
11910
11911// --- atf_amc.Msgbuf..Init
11912// Set all fields to initial values.
11913void atf_amc::Msgbuf_Init(atf_amc::Msgbuf& msgbuf) {
11914 msgbuf.in_end = 0; // in: initialize
11915 msgbuf.in_start = 0; // in: initialize
11916 msgbuf.in_eof = false; // in: initialize
11917 msgbuf.in_msgvalid = false; // in: initialize
11918 msgbuf.in_msglen = 0; // in: initialize
11919 msgbuf.in_epoll_enable = true; // in: initialize
11920 msgbuf.out_extra_end = 0; // out_extra: initialize
11921 msgbuf.out_extra_start = 0; // out_extra: initialize
11922 msgbuf.out_extra_eof = false; // out_extra: initialize
11923 msgbuf.out_extra_epoll_enable = true; // out_extra: initialize
11924 msgbuf.in_extra_end = 0; // in_extra: initialize
11925 msgbuf.in_extra_start = 0; // in_extra: initialize
11926 msgbuf.in_extra_eof = false; // in_extra: initialize
11927 msgbuf.in_extra_msgvalid = false; // in_extra: initialize
11928 msgbuf.in_extra_msglen = 0; // in_extra: initialize
11929 msgbuf.in_extra_epoll_enable = true; // in_extra: initialize
11930 msgbuf.cd_in_msg_next = (atf_amc::Msgbuf*)-1; // (atf_amc.FDb.cd_in_msg) not-in-list
11931 msgbuf.cd_in_msg_prev = NULL; // (atf_amc.FDb.cd_in_msg)
11932}
11933
11934// --- atf_amc.Msgbuf..Uninit
11935void atf_amc::Msgbuf_Uninit(atf_amc::Msgbuf& msgbuf) {
11936 atf_amc::Msgbuf &row = msgbuf; (void)row;
11937 cd_in_msg_Remove(row); // remove msgbuf from index cd_in_msg
11938}
11939
11940// --- atf_amc.Msgbuf..Print
11941// print string representation of ROW to string STR
11942// cfmt:atf_amc.Msgbuf.String printfmt:Raw
11943void atf_amc::Msgbuf_Print(atf_amc::Msgbuf& row, algo::cstring& str) {
11944 (void)row;//only to avoid -Wunused-parameter
11945 (void)str;//only to avoid -Wunused-parameter
11946}
11947
11948// --- atf_amc.MsgsCase.value.ToCstr
11949// Convert numeric value of field to one of predefined string constants.
11950// If string is found, return a static C string. Otherwise, return NULL.
11951const char* atf_amc::value_ToCstr(const atf_amc::MsgsCase& parent) {
11952 const char *ret = NULL;
11953 switch(value_GetEnum(parent)) {
11954 case atf_amc_MsgsCase_atf_amc_VarlenK: ret = "atf_amc.VarlenK"; break;
11955 }
11956 return ret;
11957}
11958
11959// --- atf_amc.MsgsCase.value.Print
11960// Convert value to a string. First, attempt conversion to a known string.
11961// If no string matches, print value as a numeric value.
11962void atf_amc::value_Print(const atf_amc::MsgsCase& parent, algo::cstring &lhs) {
11963 const char *strval = value_ToCstr(parent);
11964 if (strval) {
11965 lhs << strval;
11966 } else {
11967 lhs << parent.value;
11968 }
11969}
11970
11971// --- atf_amc.MsgsCase.value.SetStrptrMaybe
11972// Convert string to field.
11973// If the string is invalid, do not modify field and return false.
11974// In case of success, return true
11975bool atf_amc::value_SetStrptrMaybe(atf_amc::MsgsCase& parent, algo::strptr rhs) {
11976 bool ret = false;
11977 switch (elems_N(rhs)) {
11978 case 15: {
11979 switch (algo::ReadLE64(rhs.elems)) {
11980 case LE_STR8('a','t','f','_','a','m','c','.'): {
11981 if (memcmp(rhs.elems+8,"VarlenK",7)==0) { value_SetEnum(parent,atf_amc_MsgsCase_atf_amc_VarlenK); ret = true; break; }
11982 break;
11983 }
11984 }
11985 break;
11986 }
11987 }
11988 return ret;
11989}
11990
11991// --- atf_amc.MsgsCase.value.SetStrptr
11992// Convert string to field.
11993// If the string is invalid, set numeric value to DFLT
11994void atf_amc::value_SetStrptr(atf_amc::MsgsCase& parent, algo::strptr rhs, atf_amc_MsgsCaseEnum dflt) {
11995 if (!value_SetStrptrMaybe(parent,rhs)) value_SetEnum(parent,dflt);
11996}
11997
11998// --- atf_amc.MsgsCase.value.ReadStrptrMaybe
11999// Convert string to field. Return success value
12000bool atf_amc::value_ReadStrptrMaybe(atf_amc::MsgsCase& parent, algo::strptr rhs) {
12001 bool retval = false;
12002 retval = value_SetStrptrMaybe(parent,rhs); // try symbol conversion
12003 if (!retval) { // didn't work? try reading as underlying type
12004 retval = u32_ReadStrptrMaybe(parent.value,rhs);
12005 }
12006 return retval;
12007}
12008
12009// --- atf_amc.MsgsCase..ReadStrptrMaybe
12010// Read fields of atf_amc::MsgsCase from an ascii string.
12011// The format of the string is the format of the atf_amc::MsgsCase's only field
12012bool atf_amc::MsgsCase_ReadStrptrMaybe(atf_amc::MsgsCase &parent, algo::strptr in_str) {
12013 bool retval = true;
12014 retval = retval && value_ReadStrptrMaybe(parent, in_str);
12015 return retval;
12016}
12017
12018// --- atf_amc.NetBitfld1..Print
12019// print string representation of ROW to string STR
12020// cfmt:atf_amc.NetBitfld1.String printfmt:Raw
12021void atf_amc::NetBitfld1_Print(atf_amc::NetBitfld1& row, algo::cstring& str) {
12022 u16_Print(value_Get(row), str);
12023}
12024
12025// --- atf_amc.OptAlloc.typeg.Getary
12026// Access optional portion as an array of bytes
12027algo::aryptr<u8> atf_amc::typeg_Getary(atf_amc::OptAlloc& optalloc) {
12028 u8 *end = (u8*)&optalloc + sizeof(atf_amc::OptAlloc);
12029 return algo::aryptr<u8>(end, i32(optalloc.length) - ssizeof(atf_amc::OptAlloc));
12030}
12031
12032// --- atf_amc.OptAlloc.typeg.Print
12033void atf_amc::typeg_Print(atf_amc::OptAlloc& optalloc, cstring &out) {
12034 (void)out;
12035 (void)optalloc;
12036 if (atf_amc::TypeG *typeg = typeg_Get(optalloc)) {
12037 out << *typeg;
12038 }
12039}
12040
12041// --- atf_amc.OptAlloc.typeg.ReadStrptrMaybe
12042// Convert string to field. Return success value
12043bool atf_amc::typeg_ReadStrptrMaybe(atf_amc::OptAlloc &parent, algo::strptr in_str) {
12044 bool retval = false;
12045 // field cannot be read
12046 (void)parent;//only to avoid -Wunused-parameter
12047 (void)in_str;//only to avoid -Wunused-parameter
12048 return retval;
12049}
12050
12051// --- atf_amc.OptAlloc.typeg.XrefMaybe
12052// Insert row into all appropriate indices. If error occurs, store error
12053// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
12054bool atf_amc::typeg_XrefMaybe(atf_amc::TypeG &row) {
12055 bool retval = true;
12056 (void)row;
12057 return retval;
12058}
12059
12060// --- atf_amc.OptAlloc..ReadFieldMaybe
12061bool atf_amc::OptAlloc_ReadFieldMaybe(atf_amc::OptAlloc& parent, algo::strptr field, algo::strptr strval) {
12062 bool retval = true;
12063 atf_amc::FieldId field_id;
12064 (void)value_SetStrptrMaybe(field_id,field);
12065 switch(field_id) {
12066 case atf_amc_FieldId_length: {
12067 retval = false;
12068 break;
12069 }
12070 case atf_amc_FieldId_typeg: {
12071 retval = typeg_ReadStrptrMaybe(parent, strval);
12072 break;
12073 }
12074 default: break;
12075 }
12076 if (!retval) {
12077 algo_lib::AppendErrtext("attr",field);
12078 }
12079 return retval;
12080}
12081
12082// --- atf_amc.OptAlloc..ReadStrptrMaybe
12083// Any varlen fields are returned in algo_lib::_db.varlenbuf if set
12084// Read fields of atf_amc::OptAlloc from an ascii string.
12085// The format of the string is an ssim Tuple
12086bool atf_amc::OptAlloc_ReadStrptrMaybe(atf_amc::OptAlloc &parent, algo::strptr in_str) {
12087 bool retval = true;
12088 retval = algo::StripTypeTag(in_str, "atf_amc.OptAlloc");
12089 ind_beg(algo::Attr_curs, attr, in_str) {
12090 retval = retval && OptAlloc_ReadFieldMaybe(parent, attr.name, attr.value);
12091 }ind_end;
12092 return retval;
12093}
12094
12095// --- atf_amc.OptAlloc..Print
12096// print string representation of ROW to string STR
12097// cfmt:atf_amc.OptAlloc.String printfmt:Tuple
12098void atf_amc::OptAlloc_Print(atf_amc::OptAlloc& row, algo::cstring& str) {
12099 algo::tempstr temp;
12100 str << "atf_amc.OptAlloc";
12101
12102 if (typeg_Get(row)) {
12103 atf_amc::typeg_Print(row, temp);
12104 PrintAttrSpaceReset(str,"typeg", temp);
12105 }
12106}
12107
12108// --- atf_amc.OptG.typeg.Getary
12109// Access optional portion as an array of bytes
12110algo::aryptr<u8> atf_amc::typeg_Getary(atf_amc::OptG& optg) {
12111 u8 *end = (u8*)&optg + sizeof(atf_amc::OptG);
12112 return algo::aryptr<u8>(end, i32(optg.length) - ssizeof(atf_amc::OptG));
12113}
12114
12115// --- atf_amc.OptG.typeg.Print
12116void atf_amc::typeg_Print(atf_amc::OptG& optg, cstring &out) {
12117 (void)out;
12118 (void)optg;
12119 if (atf_amc::TypeG *typeg = typeg_Get(optg)) {
12120 out << *typeg;
12121 }
12122}
12123
12124// --- atf_amc.OptG.typeg.ReadStrptrMaybe
12125// Convert string to field. Return success value
12126bool atf_amc::typeg_ReadStrptrMaybe(atf_amc::OptG &parent, algo::strptr in_str) {
12127 bool retval = false;
12128 // field cannot be read
12129 (void)parent;//only to avoid -Wunused-parameter
12130 (void)in_str;//only to avoid -Wunused-parameter
12131 return retval;
12132}
12133
12134// --- atf_amc.OptG..ReadFieldMaybe
12135bool atf_amc::OptG_ReadFieldMaybe(atf_amc::OptG& parent, algo::strptr field, algo::strptr strval) {
12136 bool retval = true;
12137 atf_amc::FieldId field_id;
12138 (void)value_SetStrptrMaybe(field_id,field);
12139 switch(field_id) {
12140 case atf_amc_FieldId_length: {
12141 retval = false;
12142 break;
12143 }
12144 case atf_amc_FieldId_typeg: {
12145 retval = typeg_ReadStrptrMaybe(parent, strval);
12146 break;
12147 }
12148 default: break;
12149 }
12150 if (!retval) {
12151 algo_lib::AppendErrtext("attr",field);
12152 }
12153 return retval;
12154}
12155
12156// --- atf_amc.OptG..ReadStrptrMaybe
12157// Any varlen fields are returned in algo_lib::_db.varlenbuf if set
12158// Read fields of atf_amc::OptG from an ascii string.
12159// The format of the string is an ssim Tuple
12160bool atf_amc::OptG_ReadStrptrMaybe(atf_amc::OptG &parent, algo::strptr in_str) {
12161 bool retval = true;
12162 retval = algo::StripTypeTag(in_str, "atf_amc.OptG");
12163 ind_beg(algo::Attr_curs, attr, in_str) {
12164 retval = retval && OptG_ReadFieldMaybe(parent, attr.name, attr.value);
12165 }ind_end;
12166 return retval;
12167}
12168
12169// --- atf_amc.OptG..Print
12170// print string representation of ROW to string STR
12171// cfmt:atf_amc.OptG.String printfmt:Tuple
12172void atf_amc::OptG_Print(atf_amc::OptG& row, algo::cstring& str) {
12173 algo::tempstr temp;
12174 str << "atf_amc.OptG";
12175
12176 if (typeg_Get(row)) {
12177 atf_amc::typeg_Print(row, temp);
12178 PrintAttrSpaceReset(str,"typeg", temp);
12179 }
12180}
12181
12182// --- atf_amc.OptOptG.optg.Getary
12183// Access optional portion as an array of bytes
12184algo::aryptr<u8> atf_amc::optg_Getary(atf_amc::OptOptG& parent) {
12185 u8 *end = (u8*)&parent + sizeof(atf_amc::OptOptG);
12186 return algo::aryptr<u8>(end, i32(parent.length) - ssizeof(atf_amc::OptOptG));
12187}
12188
12189// --- atf_amc.OptOptG.optg.Print
12190void atf_amc::optg_Print(atf_amc::OptOptG& parent, cstring &out) {
12191 (void)out;
12192 (void)parent;
12193 if (atf_amc::OptG *optg = optg_Get(parent)) {
12194 out << *optg;
12195 }
12196}
12197
12198// --- atf_amc.OptOptG.optg.ReadStrptrMaybe
12199// Convert string to field. Return success value
12200bool atf_amc::optg_ReadStrptrMaybe(atf_amc::OptOptG &parent, algo::strptr in_str) {
12201 bool retval = false;
12202 if (algo::ByteAry* varlenbuf_save = algo_lib::_db.varlenbuf) {
12203 int len = sizeof(atf_amc::OptG);
12204 atf_amc::OptG *ctype = new(ary_AllocN(*varlenbuf_save, len).elems) atf_amc::OptG; // default values
12205 algo::ByteAry varlenbuf; // use for varlen msgs
12206 algo_lib::_db.varlenbuf = &varlenbuf;
12207 retval = OptG_ReadStrptrMaybe(*ctype,in_str); // read the type
12208 len += ary_N(varlenbuf);
12209 ctype->length = u32(len);
12210 ary_Addary(*varlenbuf_save, ary_Getary(varlenbuf));
12211 algo_lib::_db.varlenbuf = varlenbuf_save;
12212 }
12213 (void)parent;//only to avoid -Wunused-parameter
12214 return retval;
12215}
12216
12217// --- atf_amc.OptOptG.optg.XrefMaybe
12218// Insert row into all appropriate indices. If error occurs, store error
12219// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
12220bool atf_amc::optg_XrefMaybe(atf_amc::OptG &row) {
12221 bool retval = true;
12222 (void)row;
12223 return retval;
12224}
12225
12226// --- atf_amc.OptOptG..ReadFieldMaybe
12227bool atf_amc::OptOptG_ReadFieldMaybe(atf_amc::OptOptG& parent, algo::strptr field, algo::strptr strval) {
12228 bool retval = true;
12229 atf_amc::FieldId field_id;
12230 (void)value_SetStrptrMaybe(field_id,field);
12231 switch(field_id) {
12232 case atf_amc_FieldId_length: {
12233 retval = false;
12234 break;
12235 }
12236 case atf_amc_FieldId_optg: {
12237 retval = optg_ReadStrptrMaybe(parent, strval);
12238 break;
12239 }
12240 default: break;
12241 }
12242 if (!retval) {
12243 algo_lib::AppendErrtext("attr",field);
12244 }
12245 return retval;
12246}
12247
12248// --- atf_amc.OptOptG..ReadStrptrMaybe
12249// Any varlen fields are returned in algo_lib::_db.varlenbuf if set
12250// Read fields of atf_amc::OptOptG from an ascii string.
12251// The format of the string is an ssim Tuple
12252bool atf_amc::OptOptG_ReadStrptrMaybe(atf_amc::OptOptG &parent, algo::strptr in_str) {
12253 bool retval = true;
12254 retval = algo::StripTypeTag(in_str, "atf_amc.OptOptG");
12255 ind_beg(algo::Attr_curs, attr, in_str) {
12256 retval = retval && OptOptG_ReadFieldMaybe(parent, attr.name, attr.value);
12257 }ind_end;
12258 return retval;
12259}
12260
12261// --- atf_amc.OptOptG..Print
12262// print string representation of ROW to string STR
12263// cfmt:atf_amc.OptOptG.String printfmt:Tuple
12264void atf_amc::OptOptG_Print(atf_amc::OptOptG& row, algo::cstring& str) {
12265 algo::tempstr temp;
12266 str << "atf_amc.OptOptG";
12267
12268 if (optg_Get(row)) {
12269 atf_amc::optg_Print(row, temp);
12270 PrintAttrSpaceReset(str,"optg", temp);
12271 }
12272}
12273
12274// --- atf_amc.PmaskMultiple.value1.ReadStrptrMaybe
12275inline static bool atf_amc::value1_ReadStrptrMaybe(atf_amc::PmaskMultiple &parent, algo::strptr in_str) {
12276 bool retval = true;
12277 u32 value1_tmp;
12278 retval = u32_ReadStrptrMaybe(value1_tmp, in_str);
12279 if (retval) {
12280 value1_Set(parent, value1_tmp);
12281 }
12282 return retval;
12283}
12284
12285// --- atf_amc.PmaskMultiple.value2.ReadStrptrMaybe
12286inline static bool atf_amc::value2_ReadStrptrMaybe(atf_amc::PmaskMultiple &parent, algo::strptr in_str) {
12287 bool retval = true;
12288 u32 value2_tmp;
12289 retval = u32_ReadStrptrMaybe(value2_tmp, in_str);
12290 if (retval) {
12291 value2_Set(parent, value2_tmp);
12292 }
12293 return retval;
12294}
12295
12296// --- atf_amc.PmaskMultiple.value3.ReadStrptrMaybe
12297inline static bool atf_amc::value3_ReadStrptrMaybe(atf_amc::PmaskMultiple &parent, algo::strptr in_str) {
12298 bool retval = true;
12299 u32 value3_tmp;
12300 retval = u32_ReadStrptrMaybe(value3_tmp, in_str);
12301 if (retval) {
12302 value3_Set(parent, value3_tmp);
12303 }
12304 return retval;
12305}
12306
12307// --- atf_amc.PmaskMultiple.value4.ReadStrptrMaybe
12308inline static bool atf_amc::value4_ReadStrptrMaybe(atf_amc::PmaskMultiple &parent, algo::strptr in_str) {
12309 bool retval = true;
12310 u32 value4_tmp;
12311 retval = u32_ReadStrptrMaybe(value4_tmp, in_str);
12312 if (retval) {
12313 value4_Set(parent, value4_tmp);
12314 }
12315 return retval;
12316}
12317
12318// --- atf_amc.PmaskMultiple.value5.ReadStrptrMaybe
12319inline static bool atf_amc::value5_ReadStrptrMaybe(atf_amc::PmaskMultiple &parent, algo::strptr in_str) {
12320 bool retval = true;
12321 u32 value5_tmp;
12322 retval = u32_ReadStrptrMaybe(value5_tmp, in_str);
12323 if (retval) {
12324 value5_Set(parent, value5_tmp);
12325 }
12326 return retval;
12327}
12328
12329// --- atf_amc.PmaskMultiple.value6.ReadStrptrMaybe
12330inline static bool atf_amc::value6_ReadStrptrMaybe(atf_amc::PmaskMultiple &parent, algo::strptr in_str) {
12331 bool retval = true;
12332 u32 value6_tmp;
12333 retval = u32_ReadStrptrMaybe(value6_tmp, in_str);
12334 if (retval) {
12335 value6_Set(parent, value6_tmp);
12336 }
12337 return retval;
12338}
12339
12340// --- atf_amc.PmaskMultiple.value7.ReadStrptrMaybe
12341inline static bool atf_amc::value7_ReadStrptrMaybe(atf_amc::PmaskMultiple &parent, algo::strptr in_str) {
12342 bool retval = true;
12343 u32 value7_tmp;
12344 retval = u32_ReadStrptrMaybe(value7_tmp, in_str);
12345 if (retval) {
12346 value7_Set(parent, value7_tmp);
12347 }
12348 return retval;
12349}
12350
12351// --- atf_amc.PmaskMultiple.present_bitcurs.Next
12352// proceed to next item
12353void atf_amc::PmaskMultiple_present_bitcurs_Next(PmaskMultiple_present_bitcurs &curs) {
12354 ++curs.bit;
12355 int index = curs.bit / 32;
12356 int offset = curs.bit % 32;
12357 for (; index < curs.n_elems; ++index, offset = 0) {
12358 u64 rest = curs.elems[index] >> offset;
12359 if (rest) {
12360 offset += algo::u64_BitScanForward(rest);
12361 break;
12362 }
12363 }
12364 curs.bit = index * 32 + offset;
12365}
12366
12367// --- atf_amc.PmaskMultiple.assigned_bitcurs.Next
12368// proceed to next item
12369void atf_amc::PmaskMultiple_assigned_bitcurs_Next(PmaskMultiple_assigned_bitcurs &curs) {
12370 ++curs.bit;
12371 int index = curs.bit / 32;
12372 int offset = curs.bit % 32;
12373 for (; index < curs.n_elems; ++index, offset = 0) {
12374 u64 rest = curs.elems[index] >> offset;
12375 if (rest) {
12376 offset += algo::u64_BitScanForward(rest);
12377 break;
12378 }
12379 }
12380 curs.bit = index * 32 + offset;
12381}
12382
12383// --- atf_amc.PmaskMultiple.nullable_bitcurs.Next
12384// proceed to next item
12385void atf_amc::PmaskMultiple_nullable_bitcurs_Next(PmaskMultiple_nullable_bitcurs &curs) {
12386 ++curs.bit;
12387 int index = curs.bit / 32;
12388 int offset = curs.bit % 32;
12389 for (; index < curs.n_elems; ++index, offset = 0) {
12390 u64 rest = curs.elems[index] >> offset;
12391 if (rest) {
12392 offset += algo::u64_BitScanForward(rest);
12393 break;
12394 }
12395 }
12396 curs.bit = index * 32 + offset;
12397}
12398
12399// --- atf_amc.PmaskMultiple..ReadFieldMaybe
12400bool atf_amc::PmaskMultiple_ReadFieldMaybe(atf_amc::PmaskMultiple& parent, algo::strptr field, algo::strptr strval) {
12401 bool retval = true;
12402 atf_amc::FieldId field_id;
12403 (void)value_SetStrptrMaybe(field_id,field);
12404 switch(field_id) {
12405 case atf_amc_FieldId_present: {
12406 retval = false;
12407 break;
12408 }
12409 case atf_amc_FieldId_assigned: {
12410 retval = false;
12411 break;
12412 }
12413 case atf_amc_FieldId_nullable: {
12414 retval = false;
12415 break;
12416 }
12417 case atf_amc_FieldId_value1: {
12418 retval = value1_ReadStrptrMaybe(parent, strval);
12419 if (retval) {
12420 nullable_qSetBit(parent, 0);
12421 assigned_qSetBit(parent, 0);
12422 present_qSetBit(parent, 0);
12423 }
12424 break;
12425 }
12426 case atf_amc_FieldId_value2: {
12427 retval = value2_ReadStrptrMaybe(parent, strval);
12428 if (retval) {
12429 assigned_qSetBit(parent, 1);
12430 present_qSetBit(parent, 1);
12431 }
12432 break;
12433 }
12434 case atf_amc_FieldId_value3: {
12435 retval = value3_ReadStrptrMaybe(parent, strval);
12436 if (retval) {
12437 nullable_qSetBit(parent, 1);
12438 assigned_qSetBit(parent, 2);
12439 present_qSetBit(parent, 2);
12440 }
12441 break;
12442 }
12443 case atf_amc_FieldId_value4: {
12444 retval = value4_ReadStrptrMaybe(parent, strval);
12445 if (retval) {
12446 assigned_qSetBit(parent, 3);
12447 present_qSetBit(parent, 3);
12448 }
12449 break;
12450 }
12451 case atf_amc_FieldId_value5: {
12452 retval = value5_ReadStrptrMaybe(parent, strval);
12453 if (retval) {
12454 nullable_qSetBit(parent, 2);
12455 assigned_qSetBit(parent, 4);
12456 present_qSetBit(parent, 4);
12457 }
12458 break;
12459 }
12460 case atf_amc_FieldId_value6: {
12461 retval = value6_ReadStrptrMaybe(parent, strval);
12462 if (retval) {
12463 assigned_qSetBit(parent, 5);
12464 present_qSetBit(parent, 5);
12465 }
12466 break;
12467 }
12468 case atf_amc_FieldId_value7: {
12469 retval = value7_ReadStrptrMaybe(parent, strval);
12470 if (retval) {
12471 assigned_qSetBit(parent, 6);
12472 present_qSetBit(parent, 6);
12473 }
12474 break;
12475 }
12476 default: break;
12477 }
12478 if (!retval) {
12479 algo_lib::AppendErrtext("attr",field);
12480 }
12481 return retval;
12482}
12483
12484// --- atf_amc.PmaskMultiple..ReadStrptrMaybe
12485// Read fields of atf_amc::PmaskMultiple from an ascii string.
12486// The format of the string is an ssim Tuple
12487bool atf_amc::PmaskMultiple_ReadStrptrMaybe(atf_amc::PmaskMultiple &parent, algo::strptr in_str) {
12488 bool retval = true;
12489 retval = algo::StripTypeTag(in_str, "atf_amc.PmaskMultiple");
12490 ind_beg(algo::Attr_curs, attr, in_str) {
12491 retval = retval && PmaskMultiple_ReadFieldMaybe(parent, attr.name, attr.value);
12492 }ind_end;
12493 return retval;
12494}
12495
12496// --- atf_amc.PmaskMultiple..Init
12497// Set all fields to initial values.
12498void atf_amc::PmaskMultiple_Init(atf_amc::PmaskMultiple& parent) {
12499 parent.present = u32(0);
12500 parent.assigned = u32(0);
12501 parent.nullable = u32(0);
12502 parent.value1 = u32(0);
12503 parent.value2 = u32(0);
12504 parent.value3 = u32(0);
12505 parent.value4 = u32(0);
12506 parent.value5 = u32(0);
12507 parent.value6 = u32(0);
12508 parent.value7 = u32(0);
12509}
12510
12511// --- atf_amc.PmaskMultiple..Print
12512// print string representation of ROW to string STR
12513// cfmt:atf_amc.PmaskMultiple.String printfmt:Tuple
12514void atf_amc::PmaskMultiple_Print(atf_amc::PmaskMultiple& row, algo::cstring& str) {
12515 algo::tempstr temp;
12516 str << "atf_amc.PmaskMultiple";
12517
12518 if (value1_NullableQ(row)) {
12519 u32_Print(row.value1, temp);
12520 PrintAttrSpaceReset(str,"value1", temp);
12521 }
12522
12523 u32_Print(row.value2, temp);
12524 PrintAttrSpaceReset(str,"value2", temp);
12525
12526 if (value3_NullableQ(row)) {
12527 u32_Print(row.value3, temp);
12528 PrintAttrSpaceReset(str,"value3", temp);
12529 }
12530
12531 u32_Print(row.value4, temp);
12532 PrintAttrSpaceReset(str,"value4", temp);
12533
12534 if (value5_NullableQ(row)) {
12535 u32_Print(row.value5, temp);
12536 PrintAttrSpaceReset(str,"value5", temp);
12537 }
12538
12539 u32_Print(row.value6, temp);
12540 PrintAttrSpaceReset(str,"value6", temp);
12541
12542 u32_Print(row.value7, temp);
12543 PrintAttrSpaceReset(str,"value7", temp);
12544}
12545
12546// --- atf_amc.PmaskU128.value.ReadStrptrMaybe
12547inline static bool atf_amc::value_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12548 bool retval = true;
12549 u32 value_tmp;
12550 retval = u32_ReadStrptrMaybe(value_tmp, in_str);
12551 if (retval) {
12552 value_Set(parent, value_tmp);
12553 }
12554 return retval;
12555}
12556
12557// --- atf_amc.PmaskU128.value2.ReadStrptrMaybe
12558inline static bool atf_amc::value2_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12559 bool retval = true;
12560 u32 value2_tmp;
12561 retval = u32_ReadStrptrMaybe(value2_tmp, in_str);
12562 if (retval) {
12563 value2_Set(parent, value2_tmp);
12564 }
12565 return retval;
12566}
12567
12568// --- atf_amc.PmaskU128.value3.ReadStrptrMaybe
12569inline static bool atf_amc::value3_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12570 bool retval = true;
12571 u32 value3_tmp;
12572 retval = u32_ReadStrptrMaybe(value3_tmp, in_str);
12573 if (retval) {
12574 value3_Set(parent, value3_tmp);
12575 }
12576 return retval;
12577}
12578
12579// --- atf_amc.PmaskU128.value21.ReadStrptrMaybe
12580inline static bool atf_amc::value21_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12581 bool retval = true;
12582 u32 value21_tmp;
12583 retval = u32_ReadStrptrMaybe(value21_tmp, in_str);
12584 if (retval) {
12585 value21_Set(parent, value21_tmp);
12586 }
12587 return retval;
12588}
12589
12590// --- atf_amc.PmaskU128.value22.ReadStrptrMaybe
12591inline static bool atf_amc::value22_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12592 bool retval = true;
12593 u32 value22_tmp;
12594 retval = u32_ReadStrptrMaybe(value22_tmp, in_str);
12595 if (retval) {
12596 value22_Set(parent, value22_tmp);
12597 }
12598 return retval;
12599}
12600
12601// --- atf_amc.PmaskU128.value23.ReadStrptrMaybe
12602inline static bool atf_amc::value23_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12603 bool retval = true;
12604 u32 value23_tmp;
12605 retval = u32_ReadStrptrMaybe(value23_tmp, in_str);
12606 if (retval) {
12607 value23_Set(parent, value23_tmp);
12608 }
12609 return retval;
12610}
12611
12612// --- atf_amc.PmaskU128.value24.ReadStrptrMaybe
12613inline static bool atf_amc::value24_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12614 bool retval = true;
12615 u32 value24_tmp;
12616 retval = u32_ReadStrptrMaybe(value24_tmp, in_str);
12617 if (retval) {
12618 value24_Set(parent, value24_tmp);
12619 }
12620 return retval;
12621}
12622
12623// --- atf_amc.PmaskU128.value25.ReadStrptrMaybe
12624inline static bool atf_amc::value25_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12625 bool retval = true;
12626 u32 value25_tmp;
12627 retval = u32_ReadStrptrMaybe(value25_tmp, in_str);
12628 if (retval) {
12629 value25_Set(parent, value25_tmp);
12630 }
12631 return retval;
12632}
12633
12634// --- atf_amc.PmaskU128.value26.ReadStrptrMaybe
12635inline static bool atf_amc::value26_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12636 bool retval = true;
12637 u32 value26_tmp;
12638 retval = u32_ReadStrptrMaybe(value26_tmp, in_str);
12639 if (retval) {
12640 value26_Set(parent, value26_tmp);
12641 }
12642 return retval;
12643}
12644
12645// --- atf_amc.PmaskU128.value20.ReadStrptrMaybe
12646inline static bool atf_amc::value20_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12647 bool retval = true;
12648 u32 value20_tmp;
12649 retval = u32_ReadStrptrMaybe(value20_tmp, in_str);
12650 if (retval) {
12651 value20_Set(parent, value20_tmp);
12652 }
12653 return retval;
12654}
12655
12656// --- atf_amc.PmaskU128.value28.ReadStrptrMaybe
12657inline static bool atf_amc::value28_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12658 bool retval = true;
12659 u32 value28_tmp;
12660 retval = u32_ReadStrptrMaybe(value28_tmp, in_str);
12661 if (retval) {
12662 value28_Set(parent, value28_tmp);
12663 }
12664 return retval;
12665}
12666
12667// --- atf_amc.PmaskU128.value29.ReadStrptrMaybe
12668inline static bool atf_amc::value29_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12669 bool retval = true;
12670 u32 value29_tmp;
12671 retval = u32_ReadStrptrMaybe(value29_tmp, in_str);
12672 if (retval) {
12673 value29_Set(parent, value29_tmp);
12674 }
12675 return retval;
12676}
12677
12678// --- atf_amc.PmaskU128.value30.ReadStrptrMaybe
12679inline static bool atf_amc::value30_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12680 bool retval = true;
12681 u32 value30_tmp;
12682 retval = u32_ReadStrptrMaybe(value30_tmp, in_str);
12683 if (retval) {
12684 value30_Set(parent, value30_tmp);
12685 }
12686 return retval;
12687}
12688
12689// --- atf_amc.PmaskU128.value31.ReadStrptrMaybe
12690inline static bool atf_amc::value31_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12691 bool retval = true;
12692 u32 value31_tmp;
12693 retval = u32_ReadStrptrMaybe(value31_tmp, in_str);
12694 if (retval) {
12695 value31_Set(parent, value31_tmp);
12696 }
12697 return retval;
12698}
12699
12700// --- atf_amc.PmaskU128.value32.ReadStrptrMaybe
12701inline static bool atf_amc::value32_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12702 bool retval = true;
12703 u32 value32_tmp;
12704 retval = u32_ReadStrptrMaybe(value32_tmp, in_str);
12705 if (retval) {
12706 value32_Set(parent, value32_tmp);
12707 }
12708 return retval;
12709}
12710
12711// --- atf_amc.PmaskU128.value27.ReadStrptrMaybe
12712inline static bool atf_amc::value27_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12713 bool retval = true;
12714 u32 value27_tmp;
12715 retval = u32_ReadStrptrMaybe(value27_tmp, in_str);
12716 if (retval) {
12717 value27_Set(parent, value27_tmp);
12718 }
12719 return retval;
12720}
12721
12722// --- atf_amc.PmaskU128.value19.ReadStrptrMaybe
12723inline static bool atf_amc::value19_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12724 bool retval = true;
12725 u32 value19_tmp;
12726 retval = u32_ReadStrptrMaybe(value19_tmp, in_str);
12727 if (retval) {
12728 value19_Set(parent, value19_tmp);
12729 }
12730 return retval;
12731}
12732
12733// --- atf_amc.PmaskU128.value18.ReadStrptrMaybe
12734inline static bool atf_amc::value18_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12735 bool retval = true;
12736 u32 value18_tmp;
12737 retval = u32_ReadStrptrMaybe(value18_tmp, in_str);
12738 if (retval) {
12739 value18_Set(parent, value18_tmp);
12740 }
12741 return retval;
12742}
12743
12744// --- atf_amc.PmaskU128.value4.ReadStrptrMaybe
12745inline static bool atf_amc::value4_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12746 bool retval = true;
12747 u32 value4_tmp;
12748 retval = u32_ReadStrptrMaybe(value4_tmp, in_str);
12749 if (retval) {
12750 value4_Set(parent, value4_tmp);
12751 }
12752 return retval;
12753}
12754
12755// --- atf_amc.PmaskU128.value5.ReadStrptrMaybe
12756inline static bool atf_amc::value5_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12757 bool retval = true;
12758 u32 value5_tmp;
12759 retval = u32_ReadStrptrMaybe(value5_tmp, in_str);
12760 if (retval) {
12761 value5_Set(parent, value5_tmp);
12762 }
12763 return retval;
12764}
12765
12766// --- atf_amc.PmaskU128.value6.ReadStrptrMaybe
12767inline static bool atf_amc::value6_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12768 bool retval = true;
12769 u32 value6_tmp;
12770 retval = u32_ReadStrptrMaybe(value6_tmp, in_str);
12771 if (retval) {
12772 value6_Set(parent, value6_tmp);
12773 }
12774 return retval;
12775}
12776
12777// --- atf_amc.PmaskU128.value7.ReadStrptrMaybe
12778inline static bool atf_amc::value7_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12779 bool retval = true;
12780 u32 value7_tmp;
12781 retval = u32_ReadStrptrMaybe(value7_tmp, in_str);
12782 if (retval) {
12783 value7_Set(parent, value7_tmp);
12784 }
12785 return retval;
12786}
12787
12788// --- atf_amc.PmaskU128.value8.ReadStrptrMaybe
12789inline static bool atf_amc::value8_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12790 bool retval = true;
12791 u32 value8_tmp;
12792 retval = u32_ReadStrptrMaybe(value8_tmp, in_str);
12793 if (retval) {
12794 value8_Set(parent, value8_tmp);
12795 }
12796 return retval;
12797}
12798
12799// --- atf_amc.PmaskU128.value9.ReadStrptrMaybe
12800inline static bool atf_amc::value9_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12801 bool retval = true;
12802 u32 value9_tmp;
12803 retval = u32_ReadStrptrMaybe(value9_tmp, in_str);
12804 if (retval) {
12805 value9_Set(parent, value9_tmp);
12806 }
12807 return retval;
12808}
12809
12810// --- atf_amc.PmaskU128.value69.ReadStrptrMaybe
12811inline static bool atf_amc::value69_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12812 bool retval = true;
12813 u32 value69_tmp;
12814 retval = u32_ReadStrptrMaybe(value69_tmp, in_str);
12815 if (retval) {
12816 value69_Set(parent, value69_tmp);
12817 }
12818 return retval;
12819}
12820
12821// --- atf_amc.PmaskU128.value11.ReadStrptrMaybe
12822inline static bool atf_amc::value11_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12823 bool retval = true;
12824 u32 value11_tmp;
12825 retval = u32_ReadStrptrMaybe(value11_tmp, in_str);
12826 if (retval) {
12827 value11_Set(parent, value11_tmp);
12828 }
12829 return retval;
12830}
12831
12832// --- atf_amc.PmaskU128.value12.ReadStrptrMaybe
12833inline static bool atf_amc::value12_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12834 bool retval = true;
12835 u32 value12_tmp;
12836 retval = u32_ReadStrptrMaybe(value12_tmp, in_str);
12837 if (retval) {
12838 value12_Set(parent, value12_tmp);
12839 }
12840 return retval;
12841}
12842
12843// --- atf_amc.PmaskU128.value13.ReadStrptrMaybe
12844inline static bool atf_amc::value13_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12845 bool retval = true;
12846 u32 value13_tmp;
12847 retval = u32_ReadStrptrMaybe(value13_tmp, in_str);
12848 if (retval) {
12849 value13_Set(parent, value13_tmp);
12850 }
12851 return retval;
12852}
12853
12854// --- atf_amc.PmaskU128.value14.ReadStrptrMaybe
12855inline static bool atf_amc::value14_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12856 bool retval = true;
12857 u32 value14_tmp;
12858 retval = u32_ReadStrptrMaybe(value14_tmp, in_str);
12859 if (retval) {
12860 value14_Set(parent, value14_tmp);
12861 }
12862 return retval;
12863}
12864
12865// --- atf_amc.PmaskU128.value15.ReadStrptrMaybe
12866inline static bool atf_amc::value15_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12867 bool retval = true;
12868 u32 value15_tmp;
12869 retval = u32_ReadStrptrMaybe(value15_tmp, in_str);
12870 if (retval) {
12871 value15_Set(parent, value15_tmp);
12872 }
12873 return retval;
12874}
12875
12876// --- atf_amc.PmaskU128.value16.ReadStrptrMaybe
12877inline static bool atf_amc::value16_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12878 bool retval = true;
12879 u32 value16_tmp;
12880 retval = u32_ReadStrptrMaybe(value16_tmp, in_str);
12881 if (retval) {
12882 value16_Set(parent, value16_tmp);
12883 }
12884 return retval;
12885}
12886
12887// --- atf_amc.PmaskU128.value33.ReadStrptrMaybe
12888inline static bool atf_amc::value33_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12889 bool retval = true;
12890 u32 value33_tmp;
12891 retval = u32_ReadStrptrMaybe(value33_tmp, in_str);
12892 if (retval) {
12893 value33_Set(parent, value33_tmp);
12894 }
12895 return retval;
12896}
12897
12898// --- atf_amc.PmaskU128.value10.ReadStrptrMaybe
12899inline static bool atf_amc::value10_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12900 bool retval = true;
12901 u32 value10_tmp;
12902 retval = u32_ReadStrptrMaybe(value10_tmp, in_str);
12903 if (retval) {
12904 value10_Set(parent, value10_tmp);
12905 }
12906 return retval;
12907}
12908
12909// --- atf_amc.PmaskU128.value17.ReadStrptrMaybe
12910inline static bool atf_amc::value17_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12911 bool retval = true;
12912 u32 value17_tmp;
12913 retval = u32_ReadStrptrMaybe(value17_tmp, in_str);
12914 if (retval) {
12915 value17_Set(parent, value17_tmp);
12916 }
12917 return retval;
12918}
12919
12920// --- atf_amc.PmaskU128.value35.ReadStrptrMaybe
12921inline static bool atf_amc::value35_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12922 bool retval = true;
12923 u32 value35_tmp;
12924 retval = u32_ReadStrptrMaybe(value35_tmp, in_str);
12925 if (retval) {
12926 value35_Set(parent, value35_tmp);
12927 }
12928 return retval;
12929}
12930
12931// --- atf_amc.PmaskU128.value55.ReadStrptrMaybe
12932inline static bool atf_amc::value55_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12933 bool retval = true;
12934 u32 value55_tmp;
12935 retval = u32_ReadStrptrMaybe(value55_tmp, in_str);
12936 if (retval) {
12937 value55_Set(parent, value55_tmp);
12938 }
12939 return retval;
12940}
12941
12942// --- atf_amc.PmaskU128.value56.ReadStrptrMaybe
12943inline static bool atf_amc::value56_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12944 bool retval = true;
12945 u32 value56_tmp;
12946 retval = u32_ReadStrptrMaybe(value56_tmp, in_str);
12947 if (retval) {
12948 value56_Set(parent, value56_tmp);
12949 }
12950 return retval;
12951}
12952
12953// --- atf_amc.PmaskU128.value57.ReadStrptrMaybe
12954inline static bool atf_amc::value57_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12955 bool retval = true;
12956 u32 value57_tmp;
12957 retval = u32_ReadStrptrMaybe(value57_tmp, in_str);
12958 if (retval) {
12959 value57_Set(parent, value57_tmp);
12960 }
12961 return retval;
12962}
12963
12964// --- atf_amc.PmaskU128.value58.ReadStrptrMaybe
12965inline static bool atf_amc::value58_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12966 bool retval = true;
12967 u32 value58_tmp;
12968 retval = u32_ReadStrptrMaybe(value58_tmp, in_str);
12969 if (retval) {
12970 value58_Set(parent, value58_tmp);
12971 }
12972 return retval;
12973}
12974
12975// --- atf_amc.PmaskU128.value59.ReadStrptrMaybe
12976inline static bool atf_amc::value59_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12977 bool retval = true;
12978 u32 value59_tmp;
12979 retval = u32_ReadStrptrMaybe(value59_tmp, in_str);
12980 if (retval) {
12981 value59_Set(parent, value59_tmp);
12982 }
12983 return retval;
12984}
12985
12986// --- atf_amc.PmaskU128.value60.ReadStrptrMaybe
12987inline static bool atf_amc::value60_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12988 bool retval = true;
12989 u32 value60_tmp;
12990 retval = u32_ReadStrptrMaybe(value60_tmp, in_str);
12991 if (retval) {
12992 value60_Set(parent, value60_tmp);
12993 }
12994 return retval;
12995}
12996
12997// --- atf_amc.PmaskU128.value54.ReadStrptrMaybe
12998inline static bool atf_amc::value54_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
12999 bool retval = true;
13000 u32 value54_tmp;
13001 retval = u32_ReadStrptrMaybe(value54_tmp, in_str);
13002 if (retval) {
13003 value54_Set(parent, value54_tmp);
13004 }
13005 return retval;
13006}
13007
13008// --- atf_amc.PmaskU128.value62.ReadStrptrMaybe
13009inline static bool atf_amc::value62_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13010 bool retval = true;
13011 u32 value62_tmp;
13012 retval = u32_ReadStrptrMaybe(value62_tmp, in_str);
13013 if (retval) {
13014 value62_Set(parent, value62_tmp);
13015 }
13016 return retval;
13017}
13018
13019// --- atf_amc.PmaskU128.value63.ReadStrptrMaybe
13020inline static bool atf_amc::value63_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13021 bool retval = true;
13022 u32 value63_tmp;
13023 retval = u32_ReadStrptrMaybe(value63_tmp, in_str);
13024 if (retval) {
13025 value63_Set(parent, value63_tmp);
13026 }
13027 return retval;
13028}
13029
13030// --- atf_amc.PmaskU128.value64.ReadStrptrMaybe
13031inline static bool atf_amc::value64_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13032 bool retval = true;
13033 u32 value64_tmp;
13034 retval = u32_ReadStrptrMaybe(value64_tmp, in_str);
13035 if (retval) {
13036 value64_Set(parent, value64_tmp);
13037 }
13038 return retval;
13039}
13040
13041// --- atf_amc.PmaskU128.value65.ReadStrptrMaybe
13042inline static bool atf_amc::value65_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13043 bool retval = true;
13044 u32 value65_tmp;
13045 retval = u32_ReadStrptrMaybe(value65_tmp, in_str);
13046 if (retval) {
13047 value65_Set(parent, value65_tmp);
13048 }
13049 return retval;
13050}
13051
13052// --- atf_amc.PmaskU128.value66.ReadStrptrMaybe
13053inline static bool atf_amc::value66_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13054 bool retval = true;
13055 u32 value66_tmp;
13056 retval = u32_ReadStrptrMaybe(value66_tmp, in_str);
13057 if (retval) {
13058 value66_Set(parent, value66_tmp);
13059 }
13060 return retval;
13061}
13062
13063// --- atf_amc.PmaskU128.value67.ReadStrptrMaybe
13064inline static bool atf_amc::value67_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13065 bool retval = true;
13066 u32 value67_tmp;
13067 retval = u32_ReadStrptrMaybe(value67_tmp, in_str);
13068 if (retval) {
13069 value67_Set(parent, value67_tmp);
13070 }
13071 return retval;
13072}
13073
13074// --- atf_amc.PmaskU128.value68.ReadStrptrMaybe
13075inline static bool atf_amc::value68_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13076 bool retval = true;
13077 u32 value68_tmp;
13078 retval = u32_ReadStrptrMaybe(value68_tmp, in_str);
13079 if (retval) {
13080 value68_Set(parent, value68_tmp);
13081 }
13082 return retval;
13083}
13084
13085// --- atf_amc.PmaskU128.value61.ReadStrptrMaybe
13086inline static bool atf_amc::value61_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13087 bool retval = true;
13088 u32 value61_tmp;
13089 retval = u32_ReadStrptrMaybe(value61_tmp, in_str);
13090 if (retval) {
13091 value61_Set(parent, value61_tmp);
13092 }
13093 return retval;
13094}
13095
13096// --- atf_amc.PmaskU128.value34.ReadStrptrMaybe
13097inline static bool atf_amc::value34_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13098 bool retval = true;
13099 u32 value34_tmp;
13100 retval = u32_ReadStrptrMaybe(value34_tmp, in_str);
13101 if (retval) {
13102 value34_Set(parent, value34_tmp);
13103 }
13104 return retval;
13105}
13106
13107// --- atf_amc.PmaskU128.value52.ReadStrptrMaybe
13108inline static bool atf_amc::value52_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13109 bool retval = true;
13110 u32 value52_tmp;
13111 retval = u32_ReadStrptrMaybe(value52_tmp, in_str);
13112 if (retval) {
13113 value52_Set(parent, value52_tmp);
13114 }
13115 return retval;
13116}
13117
13118// --- atf_amc.PmaskU128.value36.ReadStrptrMaybe
13119inline static bool atf_amc::value36_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13120 bool retval = true;
13121 u32 value36_tmp;
13122 retval = u32_ReadStrptrMaybe(value36_tmp, in_str);
13123 if (retval) {
13124 value36_Set(parent, value36_tmp);
13125 }
13126 return retval;
13127}
13128
13129// --- atf_amc.PmaskU128.value37.ReadStrptrMaybe
13130inline static bool atf_amc::value37_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13131 bool retval = true;
13132 u32 value37_tmp;
13133 retval = u32_ReadStrptrMaybe(value37_tmp, in_str);
13134 if (retval) {
13135 value37_Set(parent, value37_tmp);
13136 }
13137 return retval;
13138}
13139
13140// --- atf_amc.PmaskU128.value38.ReadStrptrMaybe
13141inline static bool atf_amc::value38_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13142 bool retval = true;
13143 u32 value38_tmp;
13144 retval = u32_ReadStrptrMaybe(value38_tmp, in_str);
13145 if (retval) {
13146 value38_Set(parent, value38_tmp);
13147 }
13148 return retval;
13149}
13150
13151// --- atf_amc.PmaskU128.value39.ReadStrptrMaybe
13152inline static bool atf_amc::value39_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13153 bool retval = true;
13154 u32 value39_tmp;
13155 retval = u32_ReadStrptrMaybe(value39_tmp, in_str);
13156 if (retval) {
13157 value39_Set(parent, value39_tmp);
13158 }
13159 return retval;
13160}
13161
13162// --- atf_amc.PmaskU128.value40.ReadStrptrMaybe
13163inline static bool atf_amc::value40_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13164 bool retval = true;
13165 u32 value40_tmp;
13166 retval = u32_ReadStrptrMaybe(value40_tmp, in_str);
13167 if (retval) {
13168 value40_Set(parent, value40_tmp);
13169 }
13170 return retval;
13171}
13172
13173// --- atf_amc.PmaskU128.value41.ReadStrptrMaybe
13174inline static bool atf_amc::value41_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13175 bool retval = true;
13176 u32 value41_tmp;
13177 retval = u32_ReadStrptrMaybe(value41_tmp, in_str);
13178 if (retval) {
13179 value41_Set(parent, value41_tmp);
13180 }
13181 return retval;
13182}
13183
13184// --- atf_amc.PmaskU128.value42.ReadStrptrMaybe
13185inline static bool atf_amc::value42_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13186 bool retval = true;
13187 u32 value42_tmp;
13188 retval = u32_ReadStrptrMaybe(value42_tmp, in_str);
13189 if (retval) {
13190 value42_Set(parent, value42_tmp);
13191 }
13192 return retval;
13193}
13194
13195// --- atf_amc.PmaskU128.value53.ReadStrptrMaybe
13196inline static bool atf_amc::value53_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13197 bool retval = true;
13198 u32 value53_tmp;
13199 retval = u32_ReadStrptrMaybe(value53_tmp, in_str);
13200 if (retval) {
13201 value53_Set(parent, value53_tmp);
13202 }
13203 return retval;
13204}
13205
13206// --- atf_amc.PmaskU128.value44.ReadStrptrMaybe
13207inline static bool atf_amc::value44_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13208 bool retval = true;
13209 u32 value44_tmp;
13210 retval = u32_ReadStrptrMaybe(value44_tmp, in_str);
13211 if (retval) {
13212 value44_Set(parent, value44_tmp);
13213 }
13214 return retval;
13215}
13216
13217// --- atf_amc.PmaskU128.value45.ReadStrptrMaybe
13218inline static bool atf_amc::value45_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13219 bool retval = true;
13220 u32 value45_tmp;
13221 retval = u32_ReadStrptrMaybe(value45_tmp, in_str);
13222 if (retval) {
13223 value45_Set(parent, value45_tmp);
13224 }
13225 return retval;
13226}
13227
13228// --- atf_amc.PmaskU128.value46.ReadStrptrMaybe
13229inline static bool atf_amc::value46_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13230 bool retval = true;
13231 u32 value46_tmp;
13232 retval = u32_ReadStrptrMaybe(value46_tmp, in_str);
13233 if (retval) {
13234 value46_Set(parent, value46_tmp);
13235 }
13236 return retval;
13237}
13238
13239// --- atf_amc.PmaskU128.value47.ReadStrptrMaybe
13240inline static bool atf_amc::value47_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13241 bool retval = true;
13242 u32 value47_tmp;
13243 retval = u32_ReadStrptrMaybe(value47_tmp, in_str);
13244 if (retval) {
13245 value47_Set(parent, value47_tmp);
13246 }
13247 return retval;
13248}
13249
13250// --- atf_amc.PmaskU128.value48.ReadStrptrMaybe
13251inline static bool atf_amc::value48_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13252 bool retval = true;
13253 u32 value48_tmp;
13254 retval = u32_ReadStrptrMaybe(value48_tmp, in_str);
13255 if (retval) {
13256 value48_Set(parent, value48_tmp);
13257 }
13258 return retval;
13259}
13260
13261// --- atf_amc.PmaskU128.value49.ReadStrptrMaybe
13262inline static bool atf_amc::value49_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13263 bool retval = true;
13264 u32 value49_tmp;
13265 retval = u32_ReadStrptrMaybe(value49_tmp, in_str);
13266 if (retval) {
13267 value49_Set(parent, value49_tmp);
13268 }
13269 return retval;
13270}
13271
13272// --- atf_amc.PmaskU128.value50.ReadStrptrMaybe
13273inline static bool atf_amc::value50_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13274 bool retval = true;
13275 u32 value50_tmp;
13276 retval = u32_ReadStrptrMaybe(value50_tmp, in_str);
13277 if (retval) {
13278 value50_Set(parent, value50_tmp);
13279 }
13280 return retval;
13281}
13282
13283// --- atf_amc.PmaskU128.value51.ReadStrptrMaybe
13284inline static bool atf_amc::value51_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13285 bool retval = true;
13286 u32 value51_tmp;
13287 retval = u32_ReadStrptrMaybe(value51_tmp, in_str);
13288 if (retval) {
13289 value51_Set(parent, value51_tmp);
13290 }
13291 return retval;
13292}
13293
13294// --- atf_amc.PmaskU128.value43.ReadStrptrMaybe
13295inline static bool atf_amc::value43_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13296 bool retval = true;
13297 u32 value43_tmp;
13298 retval = u32_ReadStrptrMaybe(value43_tmp, in_str);
13299 if (retval) {
13300 value43_Set(parent, value43_tmp);
13301 }
13302 return retval;
13303}
13304
13305// --- atf_amc.PmaskU128.value70.ReadStrptrMaybe
13306inline static bool atf_amc::value70_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13307 bool retval = true;
13308 u32 value70_tmp;
13309 retval = u32_ReadStrptrMaybe(value70_tmp, in_str);
13310 if (retval) {
13311 value70_Set(parent, value70_tmp);
13312 }
13313 return retval;
13314}
13315
13316// --- atf_amc.PmaskU128.value71.ReadStrptrMaybe
13317inline static bool atf_amc::value71_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13318 bool retval = true;
13319 u32 value71_tmp;
13320 retval = u32_ReadStrptrMaybe(value71_tmp, in_str);
13321 if (retval) {
13322 value71_Set(parent, value71_tmp);
13323 }
13324 return retval;
13325}
13326
13327// --- atf_amc.PmaskU128..ReadFieldMaybe
13328bool atf_amc::PmaskU128_ReadFieldMaybe(atf_amc::PmaskU128& parent, algo::strptr field, algo::strptr strval) {
13329 bool retval = true;
13330 atf_amc::FieldId field_id;
13331 (void)value_SetStrptrMaybe(field_id,field);
13332 switch(field_id) {
13333 case atf_amc_FieldId_pmask: {
13334 retval = false;
13335 break;
13336 }
13337 case atf_amc_FieldId_value: {
13338 retval = value_ReadStrptrMaybe(parent, strval);
13339 if (retval) {
13340 pmask_qSetBit(parent, 0);
13341 }
13342 break;
13343 }
13344 case atf_amc_FieldId_value2: {
13345 retval = value2_ReadStrptrMaybe(parent, strval);
13346 if (retval) {
13347 pmask_qSetBit(parent, 1);
13348 }
13349 break;
13350 }
13351 case atf_amc_FieldId_value3: {
13352 retval = value3_ReadStrptrMaybe(parent, strval);
13353 if (retval) {
13354 pmask_qSetBit(parent, 2);
13355 }
13356 break;
13357 }
13358 case atf_amc_FieldId_value21: {
13359 retval = value21_ReadStrptrMaybe(parent, strval);
13360 if (retval) {
13361 pmask_qSetBit(parent, 3);
13362 }
13363 break;
13364 }
13365 case atf_amc_FieldId_value22: {
13366 retval = value22_ReadStrptrMaybe(parent, strval);
13367 if (retval) {
13368 pmask_qSetBit(parent, 4);
13369 }
13370 break;
13371 }
13372 case atf_amc_FieldId_value23: {
13373 retval = value23_ReadStrptrMaybe(parent, strval);
13374 if (retval) {
13375 pmask_qSetBit(parent, 5);
13376 }
13377 break;
13378 }
13379 case atf_amc_FieldId_value24: {
13380 retval = value24_ReadStrptrMaybe(parent, strval);
13381 if (retval) {
13382 pmask_qSetBit(parent, 6);
13383 }
13384 break;
13385 }
13386 case atf_amc_FieldId_value25: {
13387 retval = value25_ReadStrptrMaybe(parent, strval);
13388 if (retval) {
13389 pmask_qSetBit(parent, 7);
13390 }
13391 break;
13392 }
13393 case atf_amc_FieldId_value26: {
13394 retval = value26_ReadStrptrMaybe(parent, strval);
13395 if (retval) {
13396 pmask_qSetBit(parent, 8);
13397 }
13398 break;
13399 }
13400 case atf_amc_FieldId_value20: {
13401 retval = value20_ReadStrptrMaybe(parent, strval);
13402 if (retval) {
13403 pmask_qSetBit(parent, 9);
13404 }
13405 break;
13406 }
13407 case atf_amc_FieldId_value28: {
13408 retval = value28_ReadStrptrMaybe(parent, strval);
13409 if (retval) {
13410 pmask_qSetBit(parent, 10);
13411 }
13412 break;
13413 }
13414 case atf_amc_FieldId_value29: {
13415 retval = value29_ReadStrptrMaybe(parent, strval);
13416 if (retval) {
13417 pmask_qSetBit(parent, 11);
13418 }
13419 break;
13420 }
13421 case atf_amc_FieldId_value30: {
13422 retval = value30_ReadStrptrMaybe(parent, strval);
13423 if (retval) {
13424 pmask_qSetBit(parent, 12);
13425 }
13426 break;
13427 }
13428 case atf_amc_FieldId_value31: {
13429 retval = value31_ReadStrptrMaybe(parent, strval);
13430 if (retval) {
13431 pmask_qSetBit(parent, 13);
13432 }
13433 break;
13434 }
13435 case atf_amc_FieldId_value32: {
13436 retval = value32_ReadStrptrMaybe(parent, strval);
13437 if (retval) {
13438 pmask_qSetBit(parent, 14);
13439 }
13440 break;
13441 }
13442 case atf_amc_FieldId_value27: {
13443 retval = value27_ReadStrptrMaybe(parent, strval);
13444 if (retval) {
13445 pmask_qSetBit(parent, 15);
13446 }
13447 break;
13448 }
13449 case atf_amc_FieldId_value19: {
13450 retval = value19_ReadStrptrMaybe(parent, strval);
13451 if (retval) {
13452 pmask_qSetBit(parent, 16);
13453 }
13454 break;
13455 }
13456 case atf_amc_FieldId_value18: {
13457 retval = value18_ReadStrptrMaybe(parent, strval);
13458 if (retval) {
13459 pmask_qSetBit(parent, 17);
13460 }
13461 break;
13462 }
13463 case atf_amc_FieldId_value4: {
13464 retval = value4_ReadStrptrMaybe(parent, strval);
13465 if (retval) {
13466 pmask_qSetBit(parent, 18);
13467 }
13468 break;
13469 }
13470 case atf_amc_FieldId_value5: {
13471 retval = value5_ReadStrptrMaybe(parent, strval);
13472 if (retval) {
13473 pmask_qSetBit(parent, 19);
13474 }
13475 break;
13476 }
13477 case atf_amc_FieldId_value6: {
13478 retval = value6_ReadStrptrMaybe(parent, strval);
13479 if (retval) {
13480 pmask_qSetBit(parent, 20);
13481 }
13482 break;
13483 }
13484 case atf_amc_FieldId_value7: {
13485 retval = value7_ReadStrptrMaybe(parent, strval);
13486 if (retval) {
13487 pmask_qSetBit(parent, 21);
13488 }
13489 break;
13490 }
13491 case atf_amc_FieldId_value8: {
13492 retval = value8_ReadStrptrMaybe(parent, strval);
13493 if (retval) {
13494 pmask_qSetBit(parent, 22);
13495 }
13496 break;
13497 }
13498 case atf_amc_FieldId_value9: {
13499 retval = value9_ReadStrptrMaybe(parent, strval);
13500 if (retval) {
13501 pmask_qSetBit(parent, 23);
13502 }
13503 break;
13504 }
13505 case atf_amc_FieldId_value69: {
13506 retval = value69_ReadStrptrMaybe(parent, strval);
13507 if (retval) {
13508 pmask_qSetBit(parent, 24);
13509 }
13510 break;
13511 }
13512 case atf_amc_FieldId_value11: {
13513 retval = value11_ReadStrptrMaybe(parent, strval);
13514 if (retval) {
13515 pmask_qSetBit(parent, 25);
13516 }
13517 break;
13518 }
13519 case atf_amc_FieldId_value12: {
13520 retval = value12_ReadStrptrMaybe(parent, strval);
13521 if (retval) {
13522 pmask_qSetBit(parent, 26);
13523 }
13524 break;
13525 }
13526 case atf_amc_FieldId_value13: {
13527 retval = value13_ReadStrptrMaybe(parent, strval);
13528 if (retval) {
13529 pmask_qSetBit(parent, 27);
13530 }
13531 break;
13532 }
13533 case atf_amc_FieldId_value14: {
13534 retval = value14_ReadStrptrMaybe(parent, strval);
13535 if (retval) {
13536 pmask_qSetBit(parent, 28);
13537 }
13538 break;
13539 }
13540 case atf_amc_FieldId_value15: {
13541 retval = value15_ReadStrptrMaybe(parent, strval);
13542 if (retval) {
13543 pmask_qSetBit(parent, 29);
13544 }
13545 break;
13546 }
13547 case atf_amc_FieldId_value16: {
13548 retval = value16_ReadStrptrMaybe(parent, strval);
13549 if (retval) {
13550 pmask_qSetBit(parent, 30);
13551 }
13552 break;
13553 }
13554 case atf_amc_FieldId_value33: {
13555 retval = value33_ReadStrptrMaybe(parent, strval);
13556 if (retval) {
13557 pmask_qSetBit(parent, 31);
13558 }
13559 break;
13560 }
13561 case atf_amc_FieldId_value10: {
13562 retval = value10_ReadStrptrMaybe(parent, strval);
13563 if (retval) {
13564 pmask_qSetBit(parent, 32);
13565 }
13566 break;
13567 }
13568 case atf_amc_FieldId_value17: {
13569 retval = value17_ReadStrptrMaybe(parent, strval);
13570 if (retval) {
13571 pmask_qSetBit(parent, 33);
13572 }
13573 break;
13574 }
13575 case atf_amc_FieldId_value35: {
13576 retval = value35_ReadStrptrMaybe(parent, strval);
13577 if (retval) {
13578 pmask_qSetBit(parent, 34);
13579 }
13580 break;
13581 }
13582 case atf_amc_FieldId_value55: {
13583 retval = value55_ReadStrptrMaybe(parent, strval);
13584 if (retval) {
13585 pmask_qSetBit(parent, 35);
13586 }
13587 break;
13588 }
13589 case atf_amc_FieldId_value56: {
13590 retval = value56_ReadStrptrMaybe(parent, strval);
13591 if (retval) {
13592 pmask_qSetBit(parent, 36);
13593 }
13594 break;
13595 }
13596 case atf_amc_FieldId_value57: {
13597 retval = value57_ReadStrptrMaybe(parent, strval);
13598 if (retval) {
13599 pmask_qSetBit(parent, 37);
13600 }
13601 break;
13602 }
13603 case atf_amc_FieldId_value58: {
13604 retval = value58_ReadStrptrMaybe(parent, strval);
13605 if (retval) {
13606 pmask_qSetBit(parent, 38);
13607 }
13608 break;
13609 }
13610 case atf_amc_FieldId_value59: {
13611 retval = value59_ReadStrptrMaybe(parent, strval);
13612 if (retval) {
13613 pmask_qSetBit(parent, 39);
13614 }
13615 break;
13616 }
13617 case atf_amc_FieldId_value60: {
13618 retval = value60_ReadStrptrMaybe(parent, strval);
13619 if (retval) {
13620 pmask_qSetBit(parent, 40);
13621 }
13622 break;
13623 }
13624 case atf_amc_FieldId_value54: {
13625 retval = value54_ReadStrptrMaybe(parent, strval);
13626 if (retval) {
13627 pmask_qSetBit(parent, 41);
13628 }
13629 break;
13630 }
13631 case atf_amc_FieldId_value62: {
13632 retval = value62_ReadStrptrMaybe(parent, strval);
13633 if (retval) {
13634 pmask_qSetBit(parent, 42);
13635 }
13636 break;
13637 }
13638 case atf_amc_FieldId_value63: {
13639 retval = value63_ReadStrptrMaybe(parent, strval);
13640 if (retval) {
13641 pmask_qSetBit(parent, 43);
13642 }
13643 break;
13644 }
13645 case atf_amc_FieldId_value64: {
13646 retval = value64_ReadStrptrMaybe(parent, strval);
13647 if (retval) {
13648 pmask_qSetBit(parent, 44);
13649 }
13650 break;
13651 }
13652 case atf_amc_FieldId_value65: {
13653 retval = value65_ReadStrptrMaybe(parent, strval);
13654 if (retval) {
13655 pmask_qSetBit(parent, 45);
13656 }
13657 break;
13658 }
13659 case atf_amc_FieldId_value66: {
13660 retval = value66_ReadStrptrMaybe(parent, strval);
13661 if (retval) {
13662 pmask_qSetBit(parent, 46);
13663 }
13664 break;
13665 }
13666 case atf_amc_FieldId_value67: {
13667 retval = value67_ReadStrptrMaybe(parent, strval);
13668 if (retval) {
13669 pmask_qSetBit(parent, 47);
13670 }
13671 break;
13672 }
13673 case atf_amc_FieldId_value68: {
13674 retval = value68_ReadStrptrMaybe(parent, strval);
13675 if (retval) {
13676 pmask_qSetBit(parent, 48);
13677 }
13678 break;
13679 }
13680 case atf_amc_FieldId_value61: {
13681 retval = value61_ReadStrptrMaybe(parent, strval);
13682 if (retval) {
13683 pmask_qSetBit(parent, 49);
13684 }
13685 break;
13686 }
13687 case atf_amc_FieldId_value34: {
13688 retval = value34_ReadStrptrMaybe(parent, strval);
13689 if (retval) {
13690 pmask_qSetBit(parent, 50);
13691 }
13692 break;
13693 }
13694 case atf_amc_FieldId_value52: {
13695 retval = value52_ReadStrptrMaybe(parent, strval);
13696 if (retval) {
13697 pmask_qSetBit(parent, 51);
13698 }
13699 break;
13700 }
13701 case atf_amc_FieldId_value36: {
13702 retval = value36_ReadStrptrMaybe(parent, strval);
13703 if (retval) {
13704 pmask_qSetBit(parent, 52);
13705 }
13706 break;
13707 }
13708 case atf_amc_FieldId_value37: {
13709 retval = value37_ReadStrptrMaybe(parent, strval);
13710 if (retval) {
13711 pmask_qSetBit(parent, 53);
13712 }
13713 break;
13714 }
13715 case atf_amc_FieldId_value38: {
13716 retval = value38_ReadStrptrMaybe(parent, strval);
13717 if (retval) {
13718 pmask_qSetBit(parent, 54);
13719 }
13720 break;
13721 }
13722 case atf_amc_FieldId_value39: {
13723 retval = value39_ReadStrptrMaybe(parent, strval);
13724 if (retval) {
13725 pmask_qSetBit(parent, 55);
13726 }
13727 break;
13728 }
13729 case atf_amc_FieldId_value40: {
13730 retval = value40_ReadStrptrMaybe(parent, strval);
13731 if (retval) {
13732 pmask_qSetBit(parent, 56);
13733 }
13734 break;
13735 }
13736 case atf_amc_FieldId_value41: {
13737 retval = value41_ReadStrptrMaybe(parent, strval);
13738 if (retval) {
13739 pmask_qSetBit(parent, 57);
13740 }
13741 break;
13742 }
13743 case atf_amc_FieldId_value42: {
13744 retval = value42_ReadStrptrMaybe(parent, strval);
13745 if (retval) {
13746 pmask_qSetBit(parent, 58);
13747 }
13748 break;
13749 }
13750 case atf_amc_FieldId_value53: {
13751 retval = value53_ReadStrptrMaybe(parent, strval);
13752 if (retval) {
13753 pmask_qSetBit(parent, 59);
13754 }
13755 break;
13756 }
13757 case atf_amc_FieldId_value44: {
13758 retval = value44_ReadStrptrMaybe(parent, strval);
13759 if (retval) {
13760 pmask_qSetBit(parent, 60);
13761 }
13762 break;
13763 }
13764 case atf_amc_FieldId_value45: {
13765 retval = value45_ReadStrptrMaybe(parent, strval);
13766 if (retval) {
13767 pmask_qSetBit(parent, 61);
13768 }
13769 break;
13770 }
13771 case atf_amc_FieldId_value46: {
13772 retval = value46_ReadStrptrMaybe(parent, strval);
13773 if (retval) {
13774 pmask_qSetBit(parent, 62);
13775 }
13776 break;
13777 }
13778 case atf_amc_FieldId_value47: {
13779 retval = value47_ReadStrptrMaybe(parent, strval);
13780 if (retval) {
13781 pmask_qSetBit(parent, 63);
13782 }
13783 break;
13784 }
13785 case atf_amc_FieldId_value48: {
13786 retval = value48_ReadStrptrMaybe(parent, strval);
13787 if (retval) {
13788 pmask_qSetBit(parent, 64);
13789 }
13790 break;
13791 }
13792 case atf_amc_FieldId_value49: {
13793 retval = value49_ReadStrptrMaybe(parent, strval);
13794 if (retval) {
13795 pmask_qSetBit(parent, 65);
13796 }
13797 break;
13798 }
13799 case atf_amc_FieldId_value50: {
13800 retval = value50_ReadStrptrMaybe(parent, strval);
13801 if (retval) {
13802 pmask_qSetBit(parent, 66);
13803 }
13804 break;
13805 }
13806 case atf_amc_FieldId_value51: {
13807 retval = value51_ReadStrptrMaybe(parent, strval);
13808 if (retval) {
13809 pmask_qSetBit(parent, 67);
13810 }
13811 break;
13812 }
13813 case atf_amc_FieldId_value43: {
13814 retval = value43_ReadStrptrMaybe(parent, strval);
13815 if (retval) {
13816 pmask_qSetBit(parent, 68);
13817 }
13818 break;
13819 }
13820 case atf_amc_FieldId_value70: {
13821 retval = value70_ReadStrptrMaybe(parent, strval);
13822 if (retval) {
13823 pmask_qSetBit(parent, 69);
13824 }
13825 break;
13826 }
13827 case atf_amc_FieldId_value71: {
13828 retval = value71_ReadStrptrMaybe(parent, strval);
13829 if (retval) {
13830 pmask_qSetBit(parent, 70);
13831 }
13832 break;
13833 }
13834 default: break;
13835 }
13836 if (!retval) {
13837 algo_lib::AppendErrtext("attr",field);
13838 }
13839 return retval;
13840}
13841
13842// --- atf_amc.PmaskU128..ReadStrptrMaybe
13843// Read fields of atf_amc::PmaskU128 from an ascii string.
13844// The format of the string is an ssim Tuple
13845bool atf_amc::PmaskU128_ReadStrptrMaybe(atf_amc::PmaskU128 &parent, algo::strptr in_str) {
13846 bool retval = true;
13847 retval = algo::StripTypeTag(in_str, "atf_amc.PmaskU128");
13848 ind_beg(algo::Attr_curs, attr, in_str) {
13849 retval = retval && PmaskU128_ReadFieldMaybe(parent, attr.name, attr.value);
13850 }ind_end;
13851 return retval;
13852}
13853
13854// --- atf_amc.PmaskU128..Init
13855// Set all fields to initial values.
13856void atf_amc::PmaskU128_Init(atf_amc::PmaskU128& parent) {
13857 parent.pmask = u128(0);
13858 parent.value = u32(0);
13859 parent.value2 = u32(0);
13860 parent.value3 = u32(0);
13861 parent.value21 = u32(0);
13862 parent.value22 = u32(0);
13863 parent.value23 = u32(0);
13864 parent.value24 = u32(0);
13865 parent.value25 = u32(0);
13866 parent.value26 = u32(0);
13867 parent.value20 = u32(0);
13868 parent.value28 = u32(0);
13869 parent.value29 = u32(0);
13870 parent.value30 = u32(0);
13871 parent.value31 = u32(0);
13872 parent.value32 = u32(0);
13873 parent.value27 = u32(0);
13874 parent.value19 = u32(0);
13875 parent.value18 = u32(0);
13876 parent.value4 = u32(0);
13877 parent.value5 = u32(0);
13878 parent.value6 = u32(0);
13879 parent.value7 = u32(0);
13880 parent.value8 = u32(0);
13881 parent.value9 = u32(0);
13882 parent.value69 = u32(0);
13883 parent.value11 = u32(0);
13884 parent.value12 = u32(0);
13885 parent.value13 = u32(0);
13886 parent.value14 = u32(0);
13887 parent.value15 = u32(0);
13888 parent.value16 = u32(0);
13889 parent.value33 = u32(0);
13890 parent.value10 = u32(0);
13891 parent.value17 = u32(0);
13892 parent.value35 = u32(0);
13893 parent.value55 = u32(0);
13894 parent.value56 = u32(0);
13895 parent.value57 = u32(0);
13896 parent.value58 = u32(0);
13897 parent.value59 = u32(0);
13898 parent.value60 = u32(0);
13899 parent.value54 = u32(0);
13900 parent.value62 = u32(0);
13901 parent.value63 = u32(0);
13902 parent.value64 = u32(0);
13903 parent.value65 = u32(0);
13904 parent.value66 = u32(0);
13905 parent.value67 = u32(0);
13906 parent.value68 = u32(0);
13907 parent.value61 = u32(0);
13908 parent.value34 = u32(0);
13909 parent.value52 = u32(0);
13910 parent.value36 = u32(0);
13911 parent.value37 = u32(0);
13912 parent.value38 = u32(0);
13913 parent.value39 = u32(0);
13914 parent.value40 = u32(0);
13915 parent.value41 = u32(0);
13916 parent.value42 = u32(0);
13917 parent.value53 = u32(0);
13918 parent.value44 = u32(0);
13919 parent.value45 = u32(0);
13920 parent.value46 = u32(0);
13921 parent.value47 = u32(0);
13922 parent.value48 = u32(0);
13923 parent.value49 = u32(0);
13924 parent.value50 = u32(0);
13925 parent.value51 = u32(0);
13926 parent.value43 = u32(0);
13927 parent.value70 = u32(0);
13928 parent.value71 = u32(0);
13929}
13930
13931// --- atf_amc.PmaskU128..Print
13932// print string representation of ROW to string STR
13933// cfmt:atf_amc.PmaskU128.String printfmt:Tuple
13934void atf_amc::PmaskU128_Print(atf_amc::PmaskU128& row, algo::cstring& str) {
13935 algo::tempstr temp;
13936 str << "atf_amc.PmaskU128";
13937
13938 u32_Print(row.value, temp);
13939 PrintAttrSpaceReset(str,"value", temp);
13940
13941 u32_Print(row.value2, temp);
13942 PrintAttrSpaceReset(str,"value2", temp);
13943
13944 u32_Print(row.value3, temp);
13945 PrintAttrSpaceReset(str,"value3", temp);
13946
13947 u32_Print(row.value21, temp);
13948 PrintAttrSpaceReset(str,"value21", temp);
13949
13950 u32_Print(row.value22, temp);
13951 PrintAttrSpaceReset(str,"value22", temp);
13952
13953 u32_Print(row.value23, temp);
13954 PrintAttrSpaceReset(str,"value23", temp);
13955
13956 u32_Print(row.value24, temp);
13957 PrintAttrSpaceReset(str,"value24", temp);
13958
13959 u32_Print(row.value25, temp);
13960 PrintAttrSpaceReset(str,"value25", temp);
13961
13962 u32_Print(row.value26, temp);
13963 PrintAttrSpaceReset(str,"value26", temp);
13964
13965 u32_Print(row.value20, temp);
13966 PrintAttrSpaceReset(str,"value20", temp);
13967
13968 u32_Print(row.value28, temp);
13969 PrintAttrSpaceReset(str,"value28", temp);
13970
13971 u32_Print(row.value29, temp);
13972 PrintAttrSpaceReset(str,"value29", temp);
13973
13974 u32_Print(row.value30, temp);
13975 PrintAttrSpaceReset(str,"value30", temp);
13976
13977 u32_Print(row.value31, temp);
13978 PrintAttrSpaceReset(str,"value31", temp);
13979
13980 u32_Print(row.value32, temp);
13981 PrintAttrSpaceReset(str,"value32", temp);
13982
13983 u32_Print(row.value27, temp);
13984 PrintAttrSpaceReset(str,"value27", temp);
13985
13986 u32_Print(row.value19, temp);
13987 PrintAttrSpaceReset(str,"value19", temp);
13988
13989 u32_Print(row.value18, temp);
13990 PrintAttrSpaceReset(str,"value18", temp);
13991
13992 u32_Print(row.value4, temp);
13993 PrintAttrSpaceReset(str,"value4", temp);
13994
13995 u32_Print(row.value5, temp);
13996 PrintAttrSpaceReset(str,"value5", temp);
13997
13998 u32_Print(row.value6, temp);
13999 PrintAttrSpaceReset(str,"value6", temp);
14000
14001 u32_Print(row.value7, temp);
14002 PrintAttrSpaceReset(str,"value7", temp);
14003
14004 u32_Print(row.value8, temp);
14005 PrintAttrSpaceReset(str,"value8", temp);
14006
14007 u32_Print(row.value9, temp);
14008 PrintAttrSpaceReset(str,"value9", temp);
14009
14010 u32_Print(row.value69, temp);
14011 PrintAttrSpaceReset(str,"value69", temp);
14012
14013 u32_Print(row.value11, temp);
14014 PrintAttrSpaceReset(str,"value11", temp);
14015
14016 u32_Print(row.value12, temp);
14017 PrintAttrSpaceReset(str,"value12", temp);
14018
14019 u32_Print(row.value13, temp);
14020 PrintAttrSpaceReset(str,"value13", temp);
14021
14022 u32_Print(row.value14, temp);
14023 PrintAttrSpaceReset(str,"value14", temp);
14024
14025 u32_Print(row.value15, temp);
14026 PrintAttrSpaceReset(str,"value15", temp);
14027
14028 u32_Print(row.value16, temp);
14029 PrintAttrSpaceReset(str,"value16", temp);
14030
14031 u32_Print(row.value33, temp);
14032 PrintAttrSpaceReset(str,"value33", temp);
14033
14034 u32_Print(row.value10, temp);
14035 PrintAttrSpaceReset(str,"value10", temp);
14036
14037 u32_Print(row.value17, temp);
14038 PrintAttrSpaceReset(str,"value17", temp);
14039
14040 u32_Print(row.value35, temp);
14041 PrintAttrSpaceReset(str,"value35", temp);
14042
14043 u32_Print(row.value55, temp);
14044 PrintAttrSpaceReset(str,"value55", temp);
14045
14046 u32_Print(row.value56, temp);
14047 PrintAttrSpaceReset(str,"value56", temp);
14048
14049 u32_Print(row.value57, temp);
14050 PrintAttrSpaceReset(str,"value57", temp);
14051
14052 u32_Print(row.value58, temp);
14053 PrintAttrSpaceReset(str,"value58", temp);
14054
14055 u32_Print(row.value59, temp);
14056 PrintAttrSpaceReset(str,"value59", temp);
14057
14058 u32_Print(row.value60, temp);
14059 PrintAttrSpaceReset(str,"value60", temp);
14060
14061 u32_Print(row.value54, temp);
14062 PrintAttrSpaceReset(str,"value54", temp);
14063
14064 u32_Print(row.value62, temp);
14065 PrintAttrSpaceReset(str,"value62", temp);
14066
14067 u32_Print(row.value63, temp);
14068 PrintAttrSpaceReset(str,"value63", temp);
14069
14070 u32_Print(row.value64, temp);
14071 PrintAttrSpaceReset(str,"value64", temp);
14072
14073 u32_Print(row.value65, temp);
14074 PrintAttrSpaceReset(str,"value65", temp);
14075
14076 u32_Print(row.value66, temp);
14077 PrintAttrSpaceReset(str,"value66", temp);
14078
14079 u32_Print(row.value67, temp);
14080 PrintAttrSpaceReset(str,"value67", temp);
14081
14082 u32_Print(row.value68, temp);
14083 PrintAttrSpaceReset(str,"value68", temp);
14084
14085 u32_Print(row.value61, temp);
14086 PrintAttrSpaceReset(str,"value61", temp);
14087
14088 u32_Print(row.value34, temp);
14089 PrintAttrSpaceReset(str,"value34", temp);
14090
14091 u32_Print(row.value52, temp);
14092 PrintAttrSpaceReset(str,"value52", temp);
14093
14094 u32_Print(row.value36, temp);
14095 PrintAttrSpaceReset(str,"value36", temp);
14096
14097 u32_Print(row.value37, temp);
14098 PrintAttrSpaceReset(str,"value37", temp);
14099
14100 u32_Print(row.value38, temp);
14101 PrintAttrSpaceReset(str,"value38", temp);
14102
14103 u32_Print(row.value39, temp);
14104 PrintAttrSpaceReset(str,"value39", temp);
14105
14106 u32_Print(row.value40, temp);
14107 PrintAttrSpaceReset(str,"value40", temp);
14108
14109 u32_Print(row.value41, temp);
14110 PrintAttrSpaceReset(str,"value41", temp);
14111
14112 u32_Print(row.value42, temp);
14113 PrintAttrSpaceReset(str,"value42", temp);
14114
14115 u32_Print(row.value53, temp);
14116 PrintAttrSpaceReset(str,"value53", temp);
14117
14118 u32_Print(row.value44, temp);
14119 PrintAttrSpaceReset(str,"value44", temp);
14120
14121 u32_Print(row.value45, temp);
14122 PrintAttrSpaceReset(str,"value45", temp);
14123
14124 u32_Print(row.value46, temp);
14125 PrintAttrSpaceReset(str,"value46", temp);
14126
14127 u32_Print(row.value47, temp);
14128 PrintAttrSpaceReset(str,"value47", temp);
14129
14130 u32_Print(row.value48, temp);
14131 PrintAttrSpaceReset(str,"value48", temp);
14132
14133 u32_Print(row.value49, temp);
14134 PrintAttrSpaceReset(str,"value49", temp);
14135
14136 u32_Print(row.value50, temp);
14137 PrintAttrSpaceReset(str,"value50", temp);
14138
14139 u32_Print(row.value51, temp);
14140 PrintAttrSpaceReset(str,"value51", temp);
14141
14142 u32_Print(row.value43, temp);
14143 PrintAttrSpaceReset(str,"value43", temp);
14144
14145 u32_Print(row.value70, temp);
14146 PrintAttrSpaceReset(str,"value70", temp);
14147
14148 u32_Print(row.value71, temp);
14149 PrintAttrSpaceReset(str,"value71", temp);
14150}
14151
14152// --- atf_amc.PmaskU32.value.ReadStrptrMaybe
14153inline static bool atf_amc::value_ReadStrptrMaybe(atf_amc::PmaskU32 &parent, algo::strptr in_str) {
14154 bool retval = true;
14155 u32 value_tmp;
14156 retval = u32_ReadStrptrMaybe(value_tmp, in_str);
14157 if (retval) {
14158 value_Set(parent, value_tmp);
14159 }
14160 return retval;
14161}
14162
14163// --- atf_amc.PmaskU32.value2.ReadStrptrMaybe
14164inline static bool atf_amc::value2_ReadStrptrMaybe(atf_amc::PmaskU32 &parent, algo::strptr in_str) {
14165 bool retval = true;
14166 u32 value2_tmp;
14167 retval = u32_ReadStrptrMaybe(value2_tmp, in_str);
14168 if (retval) {
14169 value2_Set(parent, value2_tmp);
14170 }
14171 return retval;
14172}
14173
14174// --- atf_amc.PmaskU32.value3.ReadStrptrMaybe
14175inline static bool atf_amc::value3_ReadStrptrMaybe(atf_amc::PmaskU32 &parent, algo::strptr in_str) {
14176 bool retval = true;
14177 u32 value3_tmp;
14178 retval = u32_ReadStrptrMaybe(value3_tmp, in_str);
14179 if (retval) {
14180 value3_Set(parent, value3_tmp);
14181 }
14182 return retval;
14183}
14184
14185// --- atf_amc.PmaskU32.value4.ReadStrptrMaybe
14186inline static bool atf_amc::value4_ReadStrptrMaybe(atf_amc::PmaskU32 &parent, algo::strptr in_str) {
14187 bool retval = true;
14188 u32 value4_tmp;
14189 retval = u32_ReadStrptrMaybe(value4_tmp, in_str);
14190 if (retval) {
14191 value4_Set(parent, value4_tmp);
14192 }
14193 return retval;
14194}
14195
14196// --- atf_amc.PmaskU32.value5.ReadStrptrMaybe
14197inline static bool atf_amc::value5_ReadStrptrMaybe(atf_amc::PmaskU32 &parent, algo::strptr in_str) {
14198 bool retval = true;
14199 u32 value5_tmp;
14200 retval = u32_ReadStrptrMaybe(value5_tmp, in_str);
14201 if (retval) {
14202 value5_Set(parent, value5_tmp);
14203 }
14204 return retval;
14205}
14206
14207// --- atf_amc.PmaskU32.pmask_bitcurs.Next
14208// proceed to next item
14209void atf_amc::PmaskU32_pmask_bitcurs_Next(PmaskU32_pmask_bitcurs &curs) {
14210 ++curs.bit;
14211 int index = curs.bit / 32;
14212 int offset = curs.bit % 32;
14213 for (; index < curs.n_elems; ++index, offset = 0) {
14214 u64 rest = curs.elems[index] >> offset;
14215 if (rest) {
14216 offset += algo::u64_BitScanForward(rest);
14217 break;
14218 }
14219 }
14220 curs.bit = index * 32 + offset;
14221}
14222
14223// --- atf_amc.PmaskU32..ReadFieldMaybe
14224bool atf_amc::PmaskU32_ReadFieldMaybe(atf_amc::PmaskU32& parent, algo::strptr field, algo::strptr strval) {
14225 bool retval = true;
14226 atf_amc::FieldId field_id;
14227 (void)value_SetStrptrMaybe(field_id,field);
14228 switch(field_id) {
14229 case atf_amc_FieldId_pmask: {
14230 retval = false;
14231 break;
14232 }
14233 case atf_amc_FieldId_value: {
14234 retval = value_ReadStrptrMaybe(parent, strval);
14235 if (retval) {
14236 pmask_qSetBit(parent, 0);
14237 }
14238 break;
14239 }
14240 case atf_amc_FieldId_value2: {
14241 retval = value2_ReadStrptrMaybe(parent, strval);
14242 if (retval) {
14243 pmask_qSetBit(parent, 1);
14244 }
14245 break;
14246 }
14247 case atf_amc_FieldId_value3: {
14248 retval = value3_ReadStrptrMaybe(parent, strval);
14249 if (retval) {
14250 pmask_qSetBit(parent, 2);
14251 }
14252 break;
14253 }
14254 case atf_amc_FieldId_value4: {
14255 retval = value4_ReadStrptrMaybe(parent, strval);
14256 if (retval) {
14257 pmask_qSetBit(parent, 3);
14258 }
14259 break;
14260 }
14261 case atf_amc_FieldId_value5: {
14262 retval = value5_ReadStrptrMaybe(parent, strval);
14263 if (retval) {
14264 pmask_qSetBit(parent, 4);
14265 }
14266 break;
14267 }
14268 default: break;
14269 }
14270 if (!retval) {
14271 algo_lib::AppendErrtext("attr",field);
14272 }
14273 return retval;
14274}
14275
14276// --- atf_amc.PmaskU32..ReadStrptrMaybe
14277// Read fields of atf_amc::PmaskU32 from an ascii string.
14278// The format of the string is an ssim Tuple
14279bool atf_amc::PmaskU32_ReadStrptrMaybe(atf_amc::PmaskU32 &parent, algo::strptr in_str) {
14280 bool retval = true;
14281 retval = algo::StripTypeTag(in_str, "atf_amc.PmaskU32");
14282 ind_beg(algo::Attr_curs, attr, in_str) {
14283 retval = retval && PmaskU32_ReadFieldMaybe(parent, attr.name, attr.value);
14284 }ind_end;
14285 return retval;
14286}
14287
14288// --- atf_amc.PmaskU32..Print
14289// print string representation of ROW to string STR
14290// cfmt:atf_amc.PmaskU32.String printfmt:Tuple
14291void atf_amc::PmaskU32_Print(atf_amc::PmaskU32& row, algo::cstring& str) {
14292 algo::tempstr temp;
14293 str << "atf_amc.PmaskU32";
14294
14295 u32_Print(row.value, temp);
14296 PrintAttrSpaceReset(str,"value", temp);
14297
14298 u32_Print(row.value2, temp);
14299 PrintAttrSpaceReset(str,"value2", temp);
14300
14301 u32_Print(row.value3, temp);
14302 PrintAttrSpaceReset(str,"value3", temp);
14303
14304 u32_Print(row.value4, temp);
14305 PrintAttrSpaceReset(str,"value4", temp);
14306
14307 u32_Print(row.value5, temp);
14308 PrintAttrSpaceReset(str,"value5", temp);
14309}
14310
14311// --- atf_amc.PmaskU555.pmask.ReadStrptrMaybe
14312// Read array from string
14313// Convert string to field. Return success value
14314bool atf_amc::pmask_ReadStrptrMaybe(atf_amc::PmaskU555& parent, algo::strptr in_str) {
14315 bool retval = true;
14316 if (10>0) {
14317 retval = u64_ReadStrptrMaybe(parent.pmask_elems[0], in_str);
14318 }
14319 return retval;
14320}
14321
14322// --- atf_amc.PmaskU555.pmask_bitcurs.Next
14323// proceed to next item
14324void atf_amc::PmaskU555_pmask_bitcurs_Next(PmaskU555_pmask_bitcurs &curs) {
14325 ++curs.bit;
14326 int index = curs.bit / 64;
14327 int offset = curs.bit % 64;
14328 for (; index < curs.n_elems; ++index, offset = 0) {
14329 u64 rest = curs.elems[index] >> offset;
14330 if (rest) {
14331 offset += algo::u64_BitScanForward(rest);
14332 break;
14333 }
14334 }
14335 curs.bit = index * 64 + offset;
14336}
14337
14338// --- atf_amc.PooledBE64.value.ToCstr
14339// Convert numeric value of field to one of predefined string constants.
14340// If string is found, return a static C string. Otherwise, return NULL.
14341const char* atf_amc::value_ToCstr(const atf_amc::PooledBE64& pooledbe64) {
14342 const char *ret = NULL;
14343 switch(value_GetEnum(pooledbe64)) {
14344 case atf_amc_PooledBE64_value_A : ret = "A"; break;
14345 case atf_amc_PooledBE64_value_B : ret = "B"; break;
14346 }
14347 return ret;
14348}
14349
14350// --- atf_amc.PooledBE64.value.Print
14351// Convert value to a string. First, attempt conversion to a known string.
14352// If no string matches, print value as a numeric value.
14353void atf_amc::value_Print(const atf_amc::PooledBE64& pooledbe64, algo::cstring &lhs) {
14354 const char *strval = value_ToCstr(pooledbe64);
14355 if (strval) {
14356 lhs << strval;
14357 } else {
14358 lhs << value_Get(pooledbe64);
14359 }
14360}
14361
14362// --- atf_amc.PooledBE64.value.SetStrptrMaybe
14363// Convert string to field.
14364// If the string is invalid, do not modify field and return false.
14365// In case of success, return true
14366bool atf_amc::value_SetStrptrMaybe(atf_amc::PooledBE64& pooledbe64, algo::strptr rhs) {
14367 bool ret = false;
14368 switch (elems_N(rhs)) {
14369 case 1: {
14370 switch (u64(rhs[0])) {
14371 case 'A': {
14372 value_SetEnum(pooledbe64,atf_amc_PooledBE64_value_A); ret = true; break;
14373 }
14374 case 'B': {
14375 value_SetEnum(pooledbe64,atf_amc_PooledBE64_value_B); ret = true; break;
14376 }
14377 }
14378 break;
14379 }
14380 }
14381 return ret;
14382}
14383
14384// --- atf_amc.PooledBE64.value.SetStrptr
14385// Convert string to field.
14386// If the string is invalid, set numeric value to DFLT
14387void atf_amc::value_SetStrptr(atf_amc::PooledBE64& pooledbe64, algo::strptr rhs, atf_amc_PooledBE64_value_Enum dflt) {
14388 if (!value_SetStrptrMaybe(pooledbe64,rhs)) value_SetEnum(pooledbe64,dflt);
14389}
14390
14391// --- atf_amc.PooledBE64.value.ReadStrptrMaybe
14392// Convert string to field. Return success value
14393bool atf_amc::value_ReadStrptrMaybe(atf_amc::PooledBE64& pooledbe64, algo::strptr rhs) {
14394 bool retval = false;
14395 retval = value_SetStrptrMaybe(pooledbe64,rhs); // try symbol conversion
14396 if (!retval) { // didn't work? try reading as underlying type
14397 u64 value_tmp;
14398 retval = u64_ReadStrptrMaybe(value_tmp, rhs);
14399 if (retval) {
14400 value_Set(pooledbe64, value_tmp);
14401 }
14402 }
14403 return retval;
14404}
14405
14406// --- atf_amc.PooledBE64..ReadFieldMaybe
14407bool atf_amc::PooledBE64_ReadFieldMaybe(atf_amc::PooledBE64& parent, algo::strptr field, algo::strptr strval) {
14408 bool retval = true;
14409 atf_amc::FieldId field_id;
14410 (void)value_SetStrptrMaybe(field_id,field);
14411 switch(field_id) {
14412 case atf_amc_FieldId_value: {
14413 retval = value_ReadStrptrMaybe(parent, strval);
14414 break;
14415 }
14416 default: break;
14417 }
14418 if (!retval) {
14419 algo_lib::AppendErrtext("attr",field);
14420 }
14421 return retval;
14422}
14423
14424// --- atf_amc.PooledBE64..ReadStrptrMaybe
14425// Read fields of atf_amc::PooledBE64 from an ascii string.
14426// The format of the string is an ssim Tuple
14427bool atf_amc::PooledBE64_ReadStrptrMaybe(atf_amc::PooledBE64 &parent, algo::strptr in_str) {
14428 bool retval = true;
14429 retval = algo::StripTypeTag(in_str, "atf_amc.PooledBE64");
14430 ind_beg(algo::Attr_curs, attr, in_str) {
14431 retval = retval && PooledBE64_ReadFieldMaybe(parent, attr.name, attr.value);
14432 }ind_end;
14433 return retval;
14434}
14435
14436// --- atf_amc.PooledBE64..Print
14437// print string representation of ROW to string STR
14438// cfmt:atf_amc.PooledBE64.String printfmt:Tuple
14439void atf_amc::PooledBE64_Print(atf_amc::PooledBE64& row, algo::cstring& str) {
14440 algo::tempstr temp;
14441 str << "atf_amc.PooledBE64";
14442
14443 atf_amc::value_Print(row, temp);
14444 PrintAttrSpaceReset(str,"value", temp);
14445}
14446
14447// --- atf_amc.RnullStr6_U32.ch.Print
14448void atf_amc::ch_Print(atf_amc::RnullStr6_U32& parent, algo::cstring &out) {
14449 ch_Addary(out, ch_Getary(parent));
14450}
14451
14452// --- atf_amc.RnullStr6_U32.ch.ReadStrptrMaybe
14453// Convert string to field. Return success value
14454bool atf_amc::ch_ReadStrptrMaybe(atf_amc::RnullStr6_U32& parent, algo::strptr rhs) {
14455 bool retval = false;
14456 if (rhs.n_elems <= 6) {
14457 ch_SetStrptr(parent, rhs);
14458 retval = true;
14459 } else {
14460 algo_lib::SaveBadTag("comment","text too long, limit 6");
14461 }
14462 return retval;
14463}
14464
14465// --- atf_amc.RnullStr6_U32.ch.SetStrptr
14466// Copy from strptr, clipping length
14467// Set string to the value provided by RHS.
14468// If RHS is too large, it is silently clipped.
14469void atf_amc::ch_SetStrptr(atf_amc::RnullStr6_U32& parent, const algo::strptr& rhs) {
14470 int len = i32_Min(rhs.n_elems, 6);
14471 char *rhs_elems = rhs.elems;
14472 int i = 0;
14473 int j = 0;
14474 for (; i < len; i++, j++) {
14475 parent.ch[j] = rhs_elems[i];
14476 }
14477 for (; j < 6; j++) {
14478 parent.ch[j] = 0;
14479 }
14480}
14481
14482// --- atf_amc.RnullStr6_U32.ch.Getnum
14483// Convert field to numeric value. If the value is too large
14484// for the target type, or the string is invalid, the result
14485// is undefined, and and_ok is set to false.
14486// Empty string is evaluated to zero.
14487u32 atf_amc::ch_Getnum(atf_amc::RnullStr6_U32& parent, bool &and_ok) {
14488 u64 val = 0;
14489 algo::strptr str = ch_Getary(parent);
14490 if (elems_N(str)>0) { // empty string maps to zero
14491 u32 ok = 1;
14492 val = aParseNum8(str, ok);
14493 and_ok &= (ok != 0);
14494 }
14495 return u32(val);
14496}
14497
14498// --- atf_amc.RnullStr6_U32.ch.GetnumDflt
14499// Convert field to numeric value. If the value is too large
14500// for the target type, or the string is invalid, return default value.
14501// Empty string is evaluated to zero.
14502u32 atf_amc::ch_GetnumDflt(atf_amc::RnullStr6_U32& parent, u32 dflt) {
14503 bool ok = true;
14504 u32 result = ch_Getnum(parent, ok);
14505 return ok ? result : dflt;
14506}
14507
14508// --- atf_amc.RnullStr6_U32.ch.Geti64
14509// Convert field to numeric value. If the value is too large
14510// for the target type, or the string is invalid, throw an exception.
14511// Empty string is evaluated to zero.
14512i64 atf_amc::ch_Geti64(atf_amc::RnullStr6_U32& parent, bool &out_ok) {
14513 out_ok = true;
14514 i64 result = ch_Getnum(parent, out_ok);
14515 return result;
14516}
14517
14518// --- atf_amc.RnullStr6_U32.ch.SetnumMaybe
14519// Set string to number specified in RHS performing base-10 conversion.
14520// If the number is too large for the string, return false.
14521bool atf_amc::ch_SetnumMaybe(atf_amc::RnullStr6_U32& parent, i64 rhs) {
14522 char buf[128];
14523 int length = 0;
14524 int charpos = 64;
14525 u64 val = rhs;
14526 length = algo::u32_FmtBuf(val, (u8*)buf + charpos);
14527 bool retval = length <= 6;
14528 if (retval) {
14529 ch_SetStrptr(parent, algo::strptr(buf + charpos, length));
14530 }
14531 return retval;
14532}
14533
14534// --- atf_amc.RnullStr6_U32..Hash
14535u32 atf_amc::RnullStr6_U32_Hash(u32 prev, const atf_amc::RnullStr6_U32 & rhs) {
14536 algo::strptr ch_strptr = ch_Getary(rhs);
14537 prev = ::strptr_Hash(prev, ch_strptr);
14538 return prev;
14539}
14540
14541// --- atf_amc.RnullStr6_U32..ReadStrptrMaybe
14542// Read fields of atf_amc::RnullStr6_U32 from an ascii string.
14543// The format of the string is the format of the atf_amc::RnullStr6_U32's only field
14544bool atf_amc::RnullStr6_U32_ReadStrptrMaybe(atf_amc::RnullStr6_U32 &parent, algo::strptr in_str) {
14545 bool retval = true;
14546 retval = retval && ch_ReadStrptrMaybe(parent, in_str);
14547 return retval;
14548}
14549
14550// --- atf_amc.RnullStr6_U32..Print
14551// print string representation of ROW to string STR
14552// cfmt:atf_amc.RnullStr6_U32.String printfmt:Raw
14553void atf_amc::RnullStr6_U32_Print(atf_amc::RnullStr6_U32& row, algo::cstring& str) {
14554 atf_amc::ch_Print(row, str);
14555}
14556
14557// --- atf_amc.RpasU32Str6.ch.Print
14558void atf_amc::ch_Print(atf_amc::RpasU32Str6& parent, algo::cstring &out) {
14559 ch_Addary(out, ch_Getary(parent));
14560}
14561
14562// --- atf_amc.RpasU32Str6.ch.ReadStrptrMaybe
14563// Convert string to field. Return success value
14564bool atf_amc::ch_ReadStrptrMaybe(atf_amc::RpasU32Str6& parent, algo::strptr rhs) {
14565 bool retval = false;
14566 if (rhs.n_elems <= 6) {
14567 ch_SetStrptr(parent, rhs);
14568 retval = true;
14569 } else {
14570 algo_lib::SaveBadTag("comment","text too long, limit 6");
14571 }
14572 return retval;
14573}
14574
14575// --- atf_amc.RpasU32Str6.ch.SetStrptr
14576// Copy from strptr, clipping length
14577// Set string to the value provided by RHS.
14578// If RHS is too large, it is silently clipped.
14579void atf_amc::ch_SetStrptr(atf_amc::RpasU32Str6& parent, const algo::strptr& rhs) {
14580 int len = i32_Min(rhs.n_elems, 6);
14581 char *rhs_elems = rhs.elems;
14582 int i = 0;
14583 int j = 0;
14584 for (; i < len; i++, j++) {
14585 parent.ch[j] = rhs_elems[i];
14586 }
14587 parent.n_ch = u8(len);
14588}
14589
14590// --- atf_amc.RpasU32Str6.ch.Getnum
14591// Convert field to numeric value. If the value is too large
14592// for the target type, or the string is invalid, the result
14593// is undefined, and and_ok is set to false.
14594// Empty string is evaluated to zero.
14595u32 atf_amc::ch_Getnum(atf_amc::RpasU32Str6& parent, bool &and_ok) {
14596 u64 val = 0;
14597 algo::strptr str = ch_Getary(parent);
14598 if (elems_N(str)>0) { // empty string maps to zero
14599 u32 ok = 1;
14600 val = aParseNum8(str, ok);
14601 and_ok &= (ok != 0);
14602 }
14603 return u32(val);
14604}
14605
14606// --- atf_amc.RpasU32Str6.ch.GetnumDflt
14607// Convert field to numeric value. If the value is too large
14608// for the target type, or the string is invalid, return default value.
14609// Empty string is evaluated to zero.
14610u32 atf_amc::ch_GetnumDflt(atf_amc::RpasU32Str6& parent, u32 dflt) {
14611 bool ok = true;
14612 u32 result = ch_Getnum(parent, ok);
14613 return ok ? result : dflt;
14614}
14615
14616// --- atf_amc.RpasU32Str6.ch.Geti64
14617// Convert field to numeric value. If the value is too large
14618// for the target type, or the string is invalid, throw an exception.
14619// Empty string is evaluated to zero.
14620i64 atf_amc::ch_Geti64(atf_amc::RpasU32Str6& parent, bool &out_ok) {
14621 out_ok = true;
14622 i64 result = ch_Getnum(parent, out_ok);
14623 return result;
14624}
14625
14626// --- atf_amc.RpasU32Str6.ch.SetnumMaybe
14627// Set string to number specified in RHS performing base-10 conversion.
14628// If the number is too large for the string, return false.
14629bool atf_amc::ch_SetnumMaybe(atf_amc::RpasU32Str6& parent, i64 rhs) {
14630 char buf[128];
14631 int length = 0;
14632 int charpos = 64;
14633 u64 val = rhs;
14634 length = algo::u32_FmtBuf(val, (u8*)buf + charpos);
14635 bool retval = length <= 6;
14636 if (retval) {
14637 ch_SetStrptr(parent, algo::strptr(buf + charpos, length));
14638 }
14639 return retval;
14640}
14641
14642// --- atf_amc.RpasU32Str6..Hash
14643u32 atf_amc::RpasU32Str6_Hash(u32 prev, const atf_amc::RpasU32Str6 & rhs) {
14644 algo::strptr ch_strptr = ch_Getary(rhs);
14645 prev = ::strptr_Hash(prev, ch_strptr);
14646 return prev;
14647}
14648
14649// --- atf_amc.RpasU32Str6..ReadStrptrMaybe
14650// Read fields of atf_amc::RpasU32Str6 from an ascii string.
14651// The format of the string is the format of the atf_amc::RpasU32Str6's only field
14652bool atf_amc::RpasU32Str6_ReadStrptrMaybe(atf_amc::RpasU32Str6 &parent, algo::strptr in_str) {
14653 bool retval = true;
14654 retval = retval && ch_ReadStrptrMaybe(parent, in_str);
14655 return retval;
14656}
14657
14658// --- atf_amc.RpasU32Str6..Print
14659// print string representation of ROW to string STR
14660// cfmt:atf_amc.RpasU32Str6.String printfmt:Raw
14661void atf_amc::RpasU32Str6_Print(atf_amc::RpasU32Str6& row, algo::cstring& str) {
14662 atf_amc::ch_Print(row, str);
14663}
14664
14665// --- atf_amc.Sep1..ReadFieldMaybe
14666bool atf_amc::Sep1_ReadFieldMaybe(atf_amc::Sep1& parent, algo::strptr field, algo::strptr strval) {
14667 bool retval = true;
14668 atf_amc::FieldId field_id;
14669 (void)value_SetStrptrMaybe(field_id,field);
14670 switch(field_id) {
14671 case atf_amc_FieldId_val1: {
14672 retval = u32_ReadStrptrMaybe(parent.val1, strval);
14673 break;
14674 }
14675 case atf_amc_FieldId_val2: {
14676 retval = u32_ReadStrptrMaybe(parent.val2, strval);
14677 break;
14678 }
14679 case atf_amc_FieldId_val3: {
14680 retval = u32_ReadStrptrMaybe(parent.val3, strval);
14681 break;
14682 }
14683 default: break;
14684 }
14685 if (!retval) {
14686 algo_lib::AppendErrtext("attr",field);
14687 }
14688 return retval;
14689}
14690
14691// --- atf_amc.Sep1..ReadStrptrMaybe
14692// Read fields of atf_amc::Sep1 from an ascii string.
14693// The format of the string is a string with separated values
14694bool atf_amc::Sep1_ReadStrptrMaybe(atf_amc::Sep1 &parent, algo::strptr in_str) {
14695 bool retval = true;
14696 algo::strptr value;
14697
14698 algo::NextSep(in_str, '-', value);
14699 retval = retval && u32_ReadStrptrMaybe(parent.val1, value);
14700
14701 algo::NextSep(in_str, '/', value);
14702 retval = retval && u32_ReadStrptrMaybe(parent.val2, value);
14703
14704 value = in_str;
14705 retval = retval && u32_ReadStrptrMaybe(parent.val3, value);
14706 return retval;
14707}
14708
14709// --- atf_amc.Sep1..Print
14710// print string representation of ROW to string STR
14711// cfmt:atf_amc.Sep1.String printfmt:Sep
14712void atf_amc::Sep1_Print(atf_amc::Sep1& row, algo::cstring& str) {
14713 u32_Print(row.val1, str);
14714 str << '-';
14715 u32_Print(row.val2, str);
14716 str << '/';
14717 u32_Print(row.val3, str);
14718}
14719
14720// --- atf_amc.Seqmsg.msghdr.CopyOut
14721// Copy fields out of row
14722void atf_amc::parent_CopyOut(atf_amc::Seqmsg &row, atf_amc::MsgHeader &out) {
14723 // type: field value is computed
14724 // length: field value is computed
14725 (void)row;//only to avoid -Wunused-parameter
14726 (void)out;//only to avoid -Wunused-parameter
14727}
14728
14729// --- atf_amc.Seqmsg.payload.Getary
14730// Access optional portion as an array of bytes
14731algo::aryptr<u8> atf_amc::payload_Getary(atf_amc::Seqmsg& parent) {
14732 u8 *end = (u8*)&parent + sizeof(atf_amc::Seqmsg);
14733 return algo::aryptr<u8>(end, i32(parent.length) - ssizeof(atf_amc::Seqmsg));
14734}
14735
14736// --- atf_amc.Seqmsg.payload.Print
14737void atf_amc::payload_Print(atf_amc::Seqmsg& parent, cstring &out) {
14738 (void)out;
14739 (void)parent;
14740 if (atf_amc::MsgHeader *payload = payload_Get(parent)) {
14741 atf_amc::MsgHeaderMsgs_Print(out, *payload, INT_MAX);
14742 }
14743}
14744
14745// --- atf_amc.Seqmsg.payload.ReadStrptrMaybe
14746// Convert string to field. Return success value
14747bool atf_amc::payload_ReadStrptrMaybe(atf_amc::Seqmsg &parent, algo::strptr in_str) {
14748 bool retval = false;
14749 if (algo_lib::_db.varlenbuf) {
14750 algo::ByteAry temp;
14751 retval = atf_amc::MsgHeaderMsgs_ReadStrptrMaybe(in_str, temp); // read any of several message types here
14752 ary_Setary(*algo_lib::_db.varlenbuf, ary_Getary(temp)); // return it
14753 }
14754 (void)parent;//only to avoid -Wunused-parameter
14755 return retval;
14756}
14757
14758// --- atf_amc.Seqmsg..ReadFieldMaybe
14759bool atf_amc::Seqmsg_ReadFieldMaybe(atf_amc::Seqmsg& parent, algo::strptr field, algo::strptr strval) {
14760 bool retval = true;
14761 atf_amc::FieldId field_id;
14762 (void)value_SetStrptrMaybe(field_id,field);
14763 switch(field_id) {
14764 case atf_amc_FieldId_msghdr: {
14765 retval = false;
14766 break;
14767 }
14768 case atf_amc_FieldId_type: {
14769 retval = false;
14770 break;
14771 }
14772 case atf_amc_FieldId_length: {
14773 retval = false;
14774 break;
14775 }
14776 case atf_amc_FieldId_payload: {
14777 retval = payload_ReadStrptrMaybe(parent, strval);
14778 break;
14779 }
14780 default: break;
14781 }
14782 if (!retval) {
14783 algo_lib::AppendErrtext("attr",field);
14784 }
14785 return retval;
14786}
14787
14788// --- atf_amc.Seqmsg..ReadStrptrMaybe
14789// Any varlen fields are returned in algo_lib::_db.varlenbuf if set
14790// Read fields of atf_amc::Seqmsg from an ascii string.
14791// The format of the string is an ssim Tuple
14792bool atf_amc::Seqmsg_ReadStrptrMaybe(atf_amc::Seqmsg &parent, algo::strptr in_str) {
14793 bool retval = true;
14794 retval = algo::StripTypeTag(in_str, "atf_amc.Seqmsg");
14795 ind_beg(algo::Attr_curs, attr, in_str) {
14796 retval = retval && Seqmsg_ReadFieldMaybe(parent, attr.name, attr.value);
14797 }ind_end;
14798 return retval;
14799}
14800
14801// --- atf_amc.Seqmsg..Print
14802// print string representation of ROW to string STR
14803// cfmt:atf_amc.Seqmsg.String printfmt:Tuple
14804void atf_amc::Seqmsg_Print(atf_amc::Seqmsg& row, algo::cstring& str) {
14805 algo::tempstr temp;
14806 str << "atf_amc.Seqmsg";
14807
14808 if (payload_Get(row)) {
14809 atf_amc::payload_Print(row, temp);
14810 PrintAttrSpaceReset(str,"payload", temp);
14811 }
14812}
14813
14814// --- atf_amc.SortedStr.novs.Nextchar
14815// Extract next character from STR and advance IDX
14816inline static int atf_amc::novs_Nextchar(const atf_amc::SortedStr& parent, algo::strptr &str, int &idx) {
14817 (void)parent;
14818 int i = idx;
14819 int ch = str.elems[i];
14820 i++;
14821 idx = i;
14822 return ch;
14823}
14824
14825// --- atf_amc.SortedStr.vs.Nextchar
14826// Extract next character from STR and advance IDX
14827inline static u64 atf_amc::vs_Nextchar(const atf_amc::SortedStr& parent, algo::strptr &str, int &idx) {
14828 (void)parent;
14829 int i = idx;
14830 u64 ch = str.elems[i];
14831 i++;
14832 // detect number in string and eat it up into CH.
14833 // (this only works for base-10 numbers
14834 // Digits are sorted before chars
14835 if (unsigned(ch - '0') < 10) {
14836 while(i < str.n_elems) { // resulting char sorts before ascii 47
14837 unsigned dig = str.elems[i] - '0';
14838 if (dig >= 10) break;
14839 ch = ch * 10 + dig;
14840 i++;
14841 }
14842 } else if (ch > '9') {
14843 // create space between '0'..'9' for 15-digit numbers
14844 ch += 1000000000000000LL;
14845 }
14846 idx = i;
14847 return ch;
14848}
14849
14850// --- atf_amc.SortedStr.vs.Cmp
14851// Compare two fields.
14852// Comparison uses version sort (detect embedded integers).
14853// Comparison is case-insensitive.
14854i32 atf_amc::vs_Cmp(atf_amc::SortedStr& parent, atf_amc::SortedStr &rhs) {
14855 i32 retval = 0;
14856 int idx_a = 0;
14857 int idx_b = 0;
14858 algo::strptr str_a = ch_Getary(parent.vs);
14859 algo::strptr str_b = ch_Getary(rhs.vs);
14860 int n_a = elems_N(str_a);
14861 int n_b = elems_N(str_b);
14862 retval = i32_Cmp(n_a,n_b);
14863 while (idx_a < n_a && idx_b < n_b) {
14864 u64 ch_a = vs_Nextchar(parent, str_a, idx_a);
14865 u64 ch_b = vs_Nextchar(rhs, str_b, idx_b);
14866 if (ch_a != ch_b) {
14867 retval = (ch_a > ch_b)*2-1;
14868 break;
14869 }
14870 }
14871 return retval;
14872}
14873
14874// --- atf_amc.SsimfilesCase.value.ToCstr
14875// Convert numeric value of field to one of predefined string constants.
14876// If string is found, return a static C string. Otherwise, return NULL.
14877const char* atf_amc::value_ToCstr(const atf_amc::SsimfilesCase& parent) {
14878 const char *ret = NULL;
14879 switch(value_GetEnum(parent)) {
14880 case atf_amc_SsimfilesCase_dmmeta_Ctype: ret = "dmmeta.Ctype"; break;
14881 }
14882 return ret;
14883}
14884
14885// --- atf_amc.SsimfilesCase.value.Print
14886// Convert value to a string. First, attempt conversion to a known string.
14887// If no string matches, print value as a numeric value.
14888void atf_amc::value_Print(const atf_amc::SsimfilesCase& parent, algo::cstring &lhs) {
14889 const char *strval = value_ToCstr(parent);
14890 if (strval) {
14891 lhs << strval;
14892 } else {
14893 lhs << parent.value;
14894 }
14895}
14896
14897// --- atf_amc.SsimfilesCase.value.SetStrptrMaybe
14898// Convert string to field.
14899// If the string is invalid, do not modify field and return false.
14900// In case of success, return true
14901bool atf_amc::value_SetStrptrMaybe(atf_amc::SsimfilesCase& parent, algo::strptr rhs) {
14902 bool ret = false;
14903 switch (elems_N(rhs)) {
14904 case 12: {
14905 switch (algo::ReadLE64(rhs.elems)) {
14906 case LE_STR8('d','m','m','e','t','a','.','C'): {
14907 if (memcmp(rhs.elems+8,"type",4)==0) { value_SetEnum(parent,atf_amc_SsimfilesCase_dmmeta_Ctype); ret = true; break; }
14908 break;
14909 }
14910 case LE_STR8('d','m','m','e','t','a','.','c'): {
14911 if (memcmp(rhs.elems+8,"type",4)==0) { value_SetEnum(parent,atf_amc_SsimfilesCase_dmmeta_ctype); ret = true; break; }
14912 break;
14913 }
14914 }
14915 break;
14916 }
14917 }
14918 return ret;
14919}
14920
14921// --- atf_amc.SsimfilesCase.value.SetStrptr
14922// Convert string to field.
14923// If the string is invalid, set numeric value to DFLT
14924void atf_amc::value_SetStrptr(atf_amc::SsimfilesCase& parent, algo::strptr rhs, atf_amc_SsimfilesCaseEnum dflt) {
14925 if (!value_SetStrptrMaybe(parent,rhs)) value_SetEnum(parent,dflt);
14926}
14927
14928// --- atf_amc.SsimfilesCase.value.ReadStrptrMaybe
14929// Convert string to field. Return success value
14930bool atf_amc::value_ReadStrptrMaybe(atf_amc::SsimfilesCase& parent, algo::strptr rhs) {
14931 bool retval = false;
14932 retval = value_SetStrptrMaybe(parent,rhs); // try symbol conversion
14933 if (!retval) { // didn't work? try reading as underlying type
14934 retval = u32_ReadStrptrMaybe(parent.value,rhs);
14935 }
14936 return retval;
14937}
14938
14939// --- atf_amc.SsimfilesCase..ReadStrptrMaybe
14940// Read fields of atf_amc::SsimfilesCase from an ascii string.
14941// The format of the string is the format of the atf_amc::SsimfilesCase's only field
14942bool atf_amc::SsimfilesCase_ReadStrptrMaybe(atf_amc::SsimfilesCase &parent, algo::strptr in_str) {
14943 bool retval = true;
14944 retval = retval && value_ReadStrptrMaybe(parent, in_str);
14945 return retval;
14946}
14947
14948// --- atf_amc.TableId.value.ToCstr
14949// Convert numeric value of field to one of predefined string constants.
14950// If string is found, return a static C string. Otherwise, return NULL.
14951const char* atf_amc::value_ToCstr(const atf_amc::TableId& parent) {
14952 const char *ret = NULL;
14953 switch(value_GetEnum(parent)) {
14954 case atf_amc_TableId_atf_amc_TypeS : ret = "atf_amc.TypeS"; break;
14955 case atf_amc_TableId_atf_amc_TypeT : ret = "atf_amc.TypeT"; break;
14956 }
14957 return ret;
14958}
14959
14960// --- atf_amc.TableId.value.Print
14961// Convert value to a string. First, attempt conversion to a known string.
14962// If no string matches, print value as a numeric value.
14963void atf_amc::value_Print(const atf_amc::TableId& parent, algo::cstring &lhs) {
14964 const char *strval = value_ToCstr(parent);
14965 if (strval) {
14966 lhs << strval;
14967 } else {
14968 lhs << parent.value;
14969 }
14970}
14971
14972// --- atf_amc.TableId.value.SetStrptrMaybe
14973// Convert string to field.
14974// If the string is invalid, do not modify field and return false.
14975// In case of success, return true
14976bool atf_amc::value_SetStrptrMaybe(atf_amc::TableId& parent, algo::strptr rhs) {
14977 bool ret = false;
14978 switch (elems_N(rhs)) {
14979 case 13: {
14980 switch (algo::ReadLE64(rhs.elems)) {
14981 case LE_STR8('a','t','f','_','a','m','c','.'): {
14982 if (memcmp(rhs.elems+8,"TypeS",5)==0) { value_SetEnum(parent,atf_amc_TableId_atf_amc_TypeS); ret = true; break; }
14983 if (memcmp(rhs.elems+8,"TypeT",5)==0) { value_SetEnum(parent,atf_amc_TableId_atf_amc_TypeT); ret = true; break; }
14984 break;
14985 }
14986 }
14987 break;
14988 }
14989 }
14990 return ret;
14991}
14992
14993// --- atf_amc.TableId.value.SetStrptr
14994// Convert string to field.
14995// If the string is invalid, set numeric value to DFLT
14996void atf_amc::value_SetStrptr(atf_amc::TableId& parent, algo::strptr rhs, atf_amc_TableIdEnum dflt) {
14997 if (!value_SetStrptrMaybe(parent,rhs)) value_SetEnum(parent,dflt);
14998}
14999
15000// --- atf_amc.TableId.value.ReadStrptrMaybe
15001// Convert string to field. Return success value
15002bool atf_amc::value_ReadStrptrMaybe(atf_amc::TableId& parent, algo::strptr rhs) {
15003 bool retval = false;
15004 retval = value_SetStrptrMaybe(parent,rhs); // try symbol conversion
15005 if (!retval) { // didn't work? try reading as underlying type
15006 retval = i32_ReadStrptrMaybe(parent.value,rhs);
15007 }
15008 return retval;
15009}
15010
15011// --- atf_amc.TableId..ReadStrptrMaybe
15012// Read fields of atf_amc::TableId from an ascii string.
15013// The format of the string is the format of the atf_amc::TableId's only field
15014bool atf_amc::TableId_ReadStrptrMaybe(atf_amc::TableId &parent, algo::strptr in_str) {
15015 bool retval = true;
15016 retval = retval && value_ReadStrptrMaybe(parent, in_str);
15017 return retval;
15018}
15019
15020// --- atf_amc.TableId..Print
15021// print string representation of ROW to string STR
15022// cfmt:atf_amc.TableId.String printfmt:Raw
15023void atf_amc::TableId_Print(atf_amc::TableId& row, algo::cstring& str) {
15024 atf_amc::value_Print(row, str);
15025}
15026
15027// --- atf_amc.TaryU32.tary_u32.Addary
15028// Reserve space (this may move memory). Insert N element at the end.
15029// Return aryptr to newly inserted block.
15030// If the RHS argument aliases the array (refers to the same memory), exit program with fatal error.
15031algo::aryptr<u32> atf_amc::tary_u32_Addary(atf_amc::TaryU32& parent, algo::aryptr<u32> rhs) {
15032 bool overlaps = rhs.n_elems>0 && rhs.elems >= parent.tary_u32_elems && rhs.elems < parent.tary_u32_elems + parent.tary_u32_max;
15033 if (UNLIKELY(overlaps)) {
15034 FatalErrorExit("atf_amc.tary_alias field:atf_amc.TaryU32.tary_u32 comment:'alias error: sub-array is being appended to the whole'");
15035 }
15036 int nnew = rhs.n_elems;
15037 tary_u32_Reserve(parent, nnew); // reserve space
15038 int at = parent.tary_u32_n;
15039 memcpy(parent.tary_u32_elems + at, rhs.elems, nnew * sizeof(u32));
15040 parent.tary_u32_n += nnew;
15041 return algo::aryptr<u32>(parent.tary_u32_elems + at, nnew);
15042}
15043
15044// --- atf_amc.TaryU32.tary_u32.Alloc
15045// Reserve space. Insert element at the end
15046// The new element is initialized to a default value
15047u32& atf_amc::tary_u32_Alloc(atf_amc::TaryU32& parent) {
15048 tary_u32_Reserve(parent, 1);
15049 int n = parent.tary_u32_n;
15050 int at = n;
15051 u32 *elems = parent.tary_u32_elems;
15052 new (elems + at) u32(44); // construct new element, default initializer
15053 parent.tary_u32_n = n+1;
15054 return elems[at];
15055}
15056
15057// --- atf_amc.TaryU32.tary_u32.AllocAt
15058// Reserve space for new element, reallocating the array if necessary
15059// Insert new element at specified index. Index must be in range or a fatal error occurs.
15060u32& atf_amc::tary_u32_AllocAt(atf_amc::TaryU32& parent, int at) {
15061 tary_u32_Reserve(parent, 1);
15062 int n = parent.tary_u32_n;
15063 if (UNLIKELY(u64(at) >= u64(n+1))) {
15064 FatalErrorExit("atf_amc.bad_alloc_at field:atf_amc.TaryU32.tary_u32 comment:'index out of range'");
15065 }
15066 u32 *elems = parent.tary_u32_elems;
15067 memmove(elems + at + 1, elems + at, (n - at) * sizeof(u32));
15068 new (elems + at) u32(44); // construct element, default initializer
15069 parent.tary_u32_n = n+1;
15070 return elems[at];
15071}
15072
15073// --- atf_amc.TaryU32.tary_u32.AllocN
15074// Reserve space. Insert N elements at the end of the array, return pointer to array
15075algo::aryptr<u32> atf_amc::tary_u32_AllocN(atf_amc::TaryU32& parent, int n_elems) {
15076 tary_u32_Reserve(parent, n_elems);
15077 int old_n = parent.tary_u32_n;
15078 int new_n = old_n + n_elems;
15079 u32 *elems = parent.tary_u32_elems;
15080 for (int i = old_n; i < new_n; i++) {
15081 new (elems + i) u32(44); // construct new element, default initialize
15082 }
15083 parent.tary_u32_n = new_n;
15084 return algo::aryptr<u32>(elems + old_n, n_elems);
15085}
15086
15087// --- atf_amc.TaryU32.tary_u32.Remove
15088// Remove item by index. If index outside of range, do nothing.
15089void atf_amc::tary_u32_Remove(atf_amc::TaryU32& parent, u32 i) {
15090 u32 lim = parent.tary_u32_n;
15091 u32 *elems = parent.tary_u32_elems;
15092 if (i < lim) {
15093 memmove(elems + i, elems + (i + 1), sizeof(u32) * (lim - (i + 1)));
15094 parent.tary_u32_n = lim - 1;
15095 }
15096}
15097
15098// --- atf_amc.TaryU32.tary_u32.RemoveLast
15099// Delete last element of array. Do nothing if array is empty.
15100void atf_amc::tary_u32_RemoveLast(atf_amc::TaryU32& parent) {
15101 u64 n = parent.tary_u32_n;
15102 if (n > 0) {
15103 n -= 1;
15104 parent.tary_u32_n = n;
15105 }
15106}
15107
15108// --- atf_amc.TaryU32.tary_u32.AbsReserve
15109// Make sure N elements fit in array. Process dies if out of memory
15110void atf_amc::tary_u32_AbsReserve(atf_amc::TaryU32& parent, int n) {
15111 u32 old_max = parent.tary_u32_max;
15112 if (n > i32(old_max)) {
15113 u32 new_max = i32_Max(i32_Max(old_max * 2, n), 4);
15114 void *new_mem = algo_lib::malloc_ReallocMem(parent.tary_u32_elems, old_max * sizeof(u32), new_max * sizeof(u32));
15115 if (UNLIKELY(!new_mem)) {
15116 FatalErrorExit("atf_amc.tary_nomem field:atf_amc.TaryU32.tary_u32 comment:'out of memory'");
15117 }
15118 parent.tary_u32_elems = (u32*)new_mem;
15119 parent.tary_u32_max = new_max;
15120 }
15121}
15122
15123// --- atf_amc.TaryU32.tary_u32.Setary
15124// Copy contents of RHS to PARENT.
15125void atf_amc::tary_u32_Setary(atf_amc::TaryU32& parent, atf_amc::TaryU32 &rhs) {
15126 tary_u32_RemoveAll(parent);
15127 int nnew = rhs.tary_u32_n;
15128 tary_u32_Reserve(parent, nnew); // reserve space
15129 for (int i = 0; i < nnew; i++) { // copy elements over
15130 new (parent.tary_u32_elems + i) u32(tary_u32_qFind(rhs, i));
15131 parent.tary_u32_n = i + 1;
15132 }
15133}
15134
15135// --- atf_amc.TaryU32.tary_u32.Setary2
15136// Copy specified array into tary_u32, discarding previous contents.
15137// If the RHS argument aliases the array (refers to the same memory), throw exception.
15138void atf_amc::tary_u32_Setary(atf_amc::TaryU32& parent, const algo::aryptr<u32> &rhs) {
15139 tary_u32_RemoveAll(parent);
15140 tary_u32_Addary(parent, rhs);
15141}
15142
15143// --- atf_amc.TaryU32.tary_u32.AllocNVal
15144// Reserve space. Insert N elements at the end of the array, return pointer to array
15145algo::aryptr<u32> atf_amc::tary_u32_AllocNVal(atf_amc::TaryU32& parent, int n_elems, const u32& val) {
15146 tary_u32_Reserve(parent, n_elems);
15147 int old_n = parent.tary_u32_n;
15148 int new_n = old_n + n_elems;
15149 u32 *elems = parent.tary_u32_elems;
15150 for (int i = old_n; i < new_n; i++) {
15151 new (elems + i) u32(val);
15152 }
15153 parent.tary_u32_n = new_n;
15154 return algo::aryptr<u32>(elems + old_n, n_elems);
15155}
15156
15157// --- atf_amc.TaryU32.tary_u32.ReadStrptrMaybe
15158// A single element is read from input string and appended to the array.
15159// If the string contains an error, the array is untouched.
15160// Function returns success value.
15161bool atf_amc::tary_u32_ReadStrptrMaybe(atf_amc::TaryU32& parent, algo::strptr in_str) {
15162 bool retval = true;
15163 u32 &elem = tary_u32_Alloc(parent);
15164 retval = u32_ReadStrptrMaybe(elem, in_str);
15165 if (!retval) {
15166 tary_u32_RemoveLast(parent);
15167 }
15168 return retval;
15169}
15170
15171// --- atf_amc.TaryU32..Uninit
15172void atf_amc::TaryU32_Uninit(atf_amc::TaryU32& parent) {
15173 atf_amc::TaryU32 &row = parent; (void)row;
15174
15175 // atf_amc.TaryU32.tary_u32.Uninit (Tary) //
15176 // remove all elements from atf_amc.TaryU32.tary_u32
15177 tary_u32_RemoveAll(parent);
15178 // free memory for Tary atf_amc.TaryU32.tary_u32
15179 algo_lib::malloc_FreeMem(parent.tary_u32_elems, sizeof(u32)*parent.tary_u32_max); // (atf_amc.TaryU32.tary_u32)
15180}
15181
15182// --- atf_amc.TaryU8.ary.Addary
15183// Reserve space (this may move memory). Insert N element at the end.
15184// Return aryptr to newly inserted block.
15185// If the RHS argument aliases the array (refers to the same memory), exit program with fatal error.
15186algo::aryptr<u8> atf_amc::ary_Addary(atf_amc::TaryU8& parent, algo::aryptr<u8> rhs) {
15187 bool overlaps = rhs.n_elems>0 && rhs.elems >= parent.ary_elems && rhs.elems < parent.ary_elems + parent.ary_max;
15188 if (UNLIKELY(overlaps)) {
15189 FatalErrorExit("atf_amc.tary_alias field:atf_amc.TaryU8.ary comment:'alias error: sub-array is being appended to the whole'");
15190 }
15191 int nnew = rhs.n_elems;
15192 ary_Reserve(parent, nnew); // reserve space
15193 int at = parent.ary_n;
15194 memcpy(parent.ary_elems + at, rhs.elems, nnew * sizeof(u8));
15195 parent.ary_n += nnew;
15196 return algo::aryptr<u8>(parent.ary_elems + at, nnew);
15197}
15198
15199// --- atf_amc.TaryU8.ary.Alloc
15200// Reserve space. Insert element at the end
15201// The new element is initialized to a default value
15202u8& atf_amc::ary_Alloc(atf_amc::TaryU8& parent) {
15203 ary_Reserve(parent, 1);
15204 int n = parent.ary_n;
15205 int at = n;
15206 u8 *elems = parent.ary_elems;
15207 new (elems + at) u8(44); // construct new element, default initializer
15208 parent.ary_n = n+1;
15209 return elems[at];
15210}
15211
15212// --- atf_amc.TaryU8.ary.AllocAt
15213// Reserve space for new element, reallocating the array if necessary
15214// Insert new element at specified index. Index must be in range or a fatal error occurs.
15215u8& atf_amc::ary_AllocAt(atf_amc::TaryU8& parent, int at) {
15216 ary_Reserve(parent, 1);
15217 int n = parent.ary_n;
15218 if (UNLIKELY(u64(at) >= u64(n+1))) {
15219 FatalErrorExit("atf_amc.bad_alloc_at field:atf_amc.TaryU8.ary comment:'index out of range'");
15220 }
15221 u8 *elems = parent.ary_elems;
15222 memmove(elems + at + 1, elems + at, (n - at) * sizeof(u8));
15223 new (elems + at) u8(44); // construct element, default initializer
15224 parent.ary_n = n+1;
15225 return elems[at];
15226}
15227
15228// --- atf_amc.TaryU8.ary.AllocN
15229// Reserve space. Insert N elements at the end of the array, return pointer to array
15230algo::aryptr<u8> atf_amc::ary_AllocN(atf_amc::TaryU8& parent, int n_elems) {
15231 ary_Reserve(parent, n_elems);
15232 int old_n = parent.ary_n;
15233 int new_n = old_n + n_elems;
15234 u8 *elems = parent.ary_elems;
15235 memset(elems + old_n, 44, new_n - old_n); // initialize new space
15236 parent.ary_n = new_n;
15237 return algo::aryptr<u8>(elems + old_n, n_elems);
15238}
15239
15240// --- atf_amc.TaryU8.ary.Remove
15241// Remove item by index. If index outside of range, do nothing.
15242void atf_amc::ary_Remove(atf_amc::TaryU8& parent, u32 i) {
15243 u32 lim = parent.ary_n;
15244 u8 *elems = parent.ary_elems;
15245 if (i < lim) {
15246 memmove(elems + i, elems + (i + 1), sizeof(u8) * (lim - (i + 1)));
15247 parent.ary_n = lim - 1;
15248 }
15249}
15250
15251// --- atf_amc.TaryU8.ary.RemoveLast
15252// Delete last element of array. Do nothing if array is empty.
15253void atf_amc::ary_RemoveLast(atf_amc::TaryU8& parent) {
15254 u64 n = parent.ary_n;
15255 if (n > 0) {
15256 n -= 1;
15257 parent.ary_n = n;
15258 }
15259}
15260
15261// --- atf_amc.TaryU8.ary.AbsReserve
15262// Make sure N elements fit in array. Process dies if out of memory
15263void atf_amc::ary_AbsReserve(atf_amc::TaryU8& parent, int n) {
15264 u32 old_max = parent.ary_max;
15265 if (n > i32(old_max)) {
15266 u32 new_max = i32_Max(i32_Max(old_max * 2, n), 4);
15267 void *new_mem = algo_lib::malloc_ReallocMem(parent.ary_elems, old_max * sizeof(u8), new_max * sizeof(u8));
15268 if (UNLIKELY(!new_mem)) {
15269 FatalErrorExit("atf_amc.tary_nomem field:atf_amc.TaryU8.ary comment:'out of memory'");
15270 }
15271 parent.ary_elems = (u8*)new_mem;
15272 parent.ary_max = new_max;
15273 }
15274}
15275
15276// --- atf_amc.TaryU8.ary.Print
15277// Convert ary to a string.
15278// Array is printed as a regular string.
15279void atf_amc::ary_Print(atf_amc::TaryU8& parent, algo::cstring &rhs) {
15280 rhs << algo::memptr_ToStrptr(ary_Getary(parent));
15281}
15282
15283// --- atf_amc.TaryU8.ary.Setary
15284// Copy contents of RHS to PARENT.
15285void atf_amc::ary_Setary(atf_amc::TaryU8& parent, atf_amc::TaryU8 &rhs) {
15286 ary_RemoveAll(parent);
15287 int nnew = rhs.ary_n;
15288 ary_Reserve(parent, nnew); // reserve space
15289 memcpy(parent.ary_elems, rhs.ary_elems, nnew * sizeof(u8));
15290 parent.ary_n = nnew;
15291}
15292
15293// --- atf_amc.TaryU8.ary.Setary2
15294// Copy specified array into ary, discarding previous contents.
15295// If the RHS argument aliases the array (refers to the same memory), throw exception.
15296void atf_amc::ary_Setary(atf_amc::TaryU8& parent, const algo::aryptr<u8> &rhs) {
15297 ary_RemoveAll(parent);
15298 ary_Addary(parent, rhs);
15299}
15300
15301// --- atf_amc.TaryU8.ary.AllocNVal
15302// Reserve space. Insert N elements at the end of the array, return pointer to array
15303algo::aryptr<u8> atf_amc::ary_AllocNVal(atf_amc::TaryU8& parent, int n_elems, const u8& val) {
15304 ary_Reserve(parent, n_elems);
15305 int old_n = parent.ary_n;
15306 int new_n = old_n + n_elems;
15307 u8 *elems = parent.ary_elems;
15308 memset(elems + old_n, val, new_n - old_n); // initialize new space
15309 parent.ary_n = new_n;
15310 return algo::aryptr<u8>(elems + old_n, n_elems);
15311}
15312
15313// --- atf_amc.TaryU8.ary.ReadStrptrMaybe
15314// The array is replaced with the input string. Function always succeeds.
15315bool atf_amc::ary_ReadStrptrMaybe(atf_amc::TaryU8& parent, algo::strptr in_str) {
15316 bool retval = true;
15317 ary_RemoveAll(parent);
15318 ary_Addary(parent,algo::strptr_ToMemptr(in_str));
15319 return retval;
15320}
15321
15322// --- atf_amc.TaryU8..Uninit
15323void atf_amc::TaryU8_Uninit(atf_amc::TaryU8& parent) {
15324 atf_amc::TaryU8 &row = parent; (void)row;
15325
15326 // atf_amc.TaryU8.ary.Uninit (Tary) //
15327 // remove all elements from atf_amc.TaryU8.ary
15328 ary_RemoveAll(parent);
15329 // free memory for Tary atf_amc.TaryU8.ary
15330 algo_lib::malloc_FreeMem(parent.ary_elems, sizeof(u8)*parent.ary_max); // (atf_amc.TaryU8.ary)
15331}
15332
15333// --- atf_amc.TestRegx1.val.Print
15334// Print back to string
15335void atf_amc::val_Print(atf_amc::TestRegx1& parent, algo::cstring &out) {
15336 Regx_Print(parent.val, out);
15337}
15338
15339// --- atf_amc.TestRegx1.val.ReadStrptrMaybe
15340// Read Regx from string
15341// Convert string to field. Return success value
15342bool atf_amc::val_ReadStrptrMaybe(atf_amc::TestRegx1& parent, algo::strptr in) {
15343 bool retval = true;
15344 Regx_ReadSql(parent.val, in, true);
15345 return retval;
15346}
15347
15348// --- atf_amc.TestRegx1..ReadFieldMaybe
15349bool atf_amc::TestRegx1_ReadFieldMaybe(atf_amc::TestRegx1& parent, algo::strptr field, algo::strptr strval) {
15350 bool retval = true;
15351 atf_amc::FieldId field_id;
15352 (void)value_SetStrptrMaybe(field_id,field);
15353 switch(field_id) {
15354 case atf_amc_FieldId_val: {
15355 retval = val_ReadStrptrMaybe(parent, strval);
15356 break;
15357 }
15358 default: break;
15359 }
15360 if (!retval) {
15361 algo_lib::AppendErrtext("attr",field);
15362 }
15363 return retval;
15364}
15365
15366// --- atf_amc.TestRegx1..ReadStrptrMaybe
15367// Read fields of atf_amc::TestRegx1 from an ascii string.
15368// The format of the string is an ssim Tuple
15369bool atf_amc::TestRegx1_ReadStrptrMaybe(atf_amc::TestRegx1 &parent, algo::strptr in_str) {
15370 bool retval = true;
15371 retval = algo::StripTypeTag(in_str, "atf_amc.TestRegx1");
15372 ind_beg(algo::Attr_curs, attr, in_str) {
15373 retval = retval && TestRegx1_ReadFieldMaybe(parent, attr.name, attr.value);
15374 }ind_end;
15375 return retval;
15376}
15377
15378// --- atf_amc.TestRegx1..Print
15379// print string representation of ROW to string STR
15380// cfmt:atf_amc.TestRegx1.String printfmt:Tuple
15381void atf_amc::TestRegx1_Print(atf_amc::TestRegx1& row, algo::cstring& str) {
15382 algo::tempstr temp;
15383 str << "atf_amc.TestRegx1";
15384
15385 atf_amc::val_Print(row, temp);
15386 PrintAttrSpaceReset(str,"val", temp);
15387}
15388
15389// --- atf_amc.TestType..ReadStrptrMaybe
15390// Read fields of atf_amc::TestType from an ascii string.
15391bool atf_amc::TestType_ReadStrptrMaybe(atf_amc::TestType &parent, algo::strptr in_str) {
15392 bool retval = true;
15393 (void)parent;//only to avoid -Wunused-parameter
15394 (void)in_str;//only to avoid -Wunused-parameter
15395 return retval;
15396}
15397
15398// --- atf_amc.TestType..Print
15399// print string representation of ROW to string STR
15400// cfmt:atf_amc.TestType.String printfmt:Raw
15401void atf_amc::TestType_Print(atf_amc::TestType& row, algo::cstring& str) {
15402 (void)row;//only to avoid -Wunused-parameter
15403 (void)str;//only to avoid -Wunused-parameter
15404}
15405
15406// --- atf_amc.Text.msghdr.CopyOut
15407// Copy fields out of row
15408void atf_amc::parent_CopyOut(atf_amc::Text &row, atf_amc::MsgHeader &out) {
15409 // type: field value is computed
15410 // length: field value is computed
15411 (void)row;//only to avoid -Wunused-parameter
15412 (void)out;//only to avoid -Wunused-parameter
15413}
15414
15415// --- atf_amc.Text.text.Getary
15416// Access var-length portion as an aryptr. Length is determined from one of the fields.
15417algo::aryptr<char> atf_amc::text_Getary(atf_amc::Text& parent) {
15418 return algo::aryptr<char>(text_Addr(parent), text_N(parent));
15419}
15420
15421// --- atf_amc.Text.text.Addr
15422char* atf_amc::text_Addr(atf_amc::Text& parent) {
15423 return (char*)((u8*)&parent + sizeof(atf_amc::Text)); // address of varlen portion
15424}
15425
15426// --- atf_amc.Text.text.ReadStrptrMaybe
15427// Convert string to field. Return success value
15428bool atf_amc::text_ReadStrptrMaybe(atf_amc::Text& parent, algo::strptr in_str) {
15429 bool retval = true;
15430 if (algo_lib::_db.varlenbuf) {
15431 ary_Addary(*algo_lib::_db.varlenbuf, strptr_ToMemptr(in_str));
15432 }
15433 (void)parent;//only to avoid -Wunused-parameter
15434 return retval;
15435}
15436
15437// --- atf_amc.Text.text.Print
15438// Convert text to a string.
15439// Array is printed as a regular string.
15440void atf_amc::text_Print(atf_amc::Text& parent, algo::cstring &rhs) {
15441 rhs << text_Getary(parent);
15442}
15443
15444// --- atf_amc.Text..ReadFieldMaybe
15445bool atf_amc::Text_ReadFieldMaybe(atf_amc::Text& parent, algo::strptr field, algo::strptr strval) {
15446 bool retval = true;
15447 atf_amc::FieldId field_id;
15448 (void)value_SetStrptrMaybe(field_id,algo::Pathcomp(field, ".LL"));
15449 switch(field_id) {
15450 case atf_amc_FieldId_msghdr: {
15451 retval = false;
15452 break;
15453 }
15454 case atf_amc_FieldId_type: {
15455 retval = false;
15456 break;
15457 }
15458 case atf_amc_FieldId_length: {
15459 retval = false;
15460 break;
15461 }
15462 case atf_amc_FieldId_text: {
15463 retval = text_ReadStrptrMaybe(parent, strval);
15464 break;
15465 }
15466 default: break;
15467 }
15468 if (!retval) {
15469 algo_lib::AppendErrtext("attr",field);
15470 }
15471 return retval;
15472}
15473
15474// --- atf_amc.Text..ReadStrptrMaybe
15475// Any varlen fields are returned in algo_lib::_db.varlenbuf if set
15476// Read fields of atf_amc::Text from an ascii string.
15477// The format of the string is an ssim Tuple
15478bool atf_amc::Text_ReadStrptrMaybe(atf_amc::Text &parent, algo::strptr in_str) {
15479 bool retval = true;
15480 retval = algo::StripTypeTag(in_str, "atf_amc.Text");
15481 ind_beg(algo::Attr_curs, attr, in_str) {
15482 retval = retval && Text_ReadFieldMaybe(parent, attr.name, attr.value);
15483 }ind_end;
15484 return retval;
15485}
15486
15487// --- atf_amc.Text..Print
15488// print string representation of ROW to string STR
15489// cfmt:atf_amc.Text.String printfmt:Tuple
15490void atf_amc::Text_Print(atf_amc::Text& row, algo::cstring& str) {
15491 algo::tempstr temp;
15492 str << "atf_amc.Text";
15493
15494 atf_amc::text_Print(row, temp);
15495 PrintAttrSpaceReset(str,"text", temp);
15496}
15497
15498// --- atf_amc.TypeB..ReadFieldMaybe
15499bool atf_amc::TypeB_ReadFieldMaybe(atf_amc::TypeB& parent, algo::strptr field, algo::strptr strval) {
15500 bool retval = true;
15501 atf_amc::FieldId field_id;
15502 (void)value_SetStrptrMaybe(field_id,field);
15503 switch(field_id) {
15504 case atf_amc_FieldId_typea: {
15505 retval = i32_ReadStrptrMaybe(parent.typea, strval);
15506 break;
15507 }
15508 case atf_amc_FieldId_j: {
15509 retval = i32_ReadStrptrMaybe(parent.j, strval);
15510 break;
15511 }
15512 default: break;
15513 }
15514 if (!retval) {
15515 algo_lib::AppendErrtext("attr",field);
15516 }
15517 return retval;
15518}
15519
15520// --- atf_amc.TypeB..ReadStrptrMaybe
15521// Read fields of atf_amc::TypeB from an ascii string.
15522// The format of the string is an ssim Tuple
15523bool atf_amc::TypeB_ReadStrptrMaybe(atf_amc::TypeB &parent, algo::strptr in_str) {
15524 bool retval = true;
15525 retval = algo::StripTypeTag(in_str, "atf_amc.TypeB");
15526 ind_beg(algo::Attr_curs, attr, in_str) {
15527 retval = retval && TypeB_ReadFieldMaybe(parent, attr.name, attr.value);
15528 }ind_end;
15529 return retval;
15530}
15531
15532// --- atf_amc.TypeB..FmtJson
15533// Create JSON representation of atf_amc::TypeB under PARENT node
15534// cfmt:atf_amc.TypeB.Json printfmt:Auto
15535lib_json::FNode * atf_amc::TypeB_FmtJson(atf_amc::TypeB& row, lib_json::FNode *parent) {
15536 lib_json::FNode *object_node = &lib_json::node_Alloc();
15537 object_node->p_parent = parent?parent:object_node;
15538 object_node->type = lib_json_FNode_type_object;
15539 node_XrefMaybe(*object_node);
15540
15541 lib_json::FNode *typea_field_node = &lib_json::node_Alloc();
15542 typea_field_node->p_parent = object_node;
15543 typea_field_node->type = lib_json_FNode_type_field;
15544 typea_field_node->value = "typea";
15545 node_XrefMaybe(*typea_field_node);
15546 i32_FmtJson(const_cast<atf_amc::TypeB&>(row).typea,typea_field_node);
15547
15548 lib_json::FNode *j_field_node = &lib_json::node_Alloc();
15549 j_field_node->p_parent = object_node;
15550 j_field_node->type = lib_json_FNode_type_field;
15551 j_field_node->value = "j";
15552 node_XrefMaybe(*j_field_node);
15553 i32_FmtJson(const_cast<atf_amc::TypeB&>(row).j,j_field_node);
15554 return object_node;
15555}
15556
15557// --- atf_amc.TypeB..Print
15558// print string representation of ROW to string STR
15559// cfmt:atf_amc.TypeB.String printfmt:Tuple
15560void atf_amc::TypeB_Print(atf_amc::TypeB& row, algo::cstring& str) {
15561 algo::tempstr temp;
15562 str << "atf_amc.TypeB";
15563
15564 i32_Print(row.typea, temp);
15565 PrintAttrSpaceReset(str,"typea", temp);
15566
15567 i32_Print(row.j, temp);
15568 PrintAttrSpaceReset(str,"j", temp);
15569}
15570
15571// --- atf_amc.TypeBE32en.value.ToCstr
15572// Convert numeric value of field to one of predefined string constants.
15573// If string is found, return a static C string. Otherwise, return NULL.
15574const char* atf_amc::value_ToCstr(const atf_amc::TypeBE32en& parent) {
15575 const char *ret = NULL;
15576 switch(value_GetEnum(parent)) {
15577 case atf_amc_TypeBE32en_value_val1 : ret = "val1"; break;
15578 case atf_amc_TypeBE32en_value_val2 : ret = "val2"; break;
15579 }
15580 return ret;
15581}
15582
15583// --- atf_amc.TypeBE32en.value.Print
15584// Convert value to a string. First, attempt conversion to a known string.
15585// If no string matches, print value as a numeric value.
15586void atf_amc::value_Print(const atf_amc::TypeBE32en& parent, algo::cstring &lhs) {
15587 const char *strval = value_ToCstr(parent);
15588 if (strval) {
15589 lhs << strval;
15590 } else {
15591 lhs << value_Get(parent);
15592 }
15593}
15594
15595// --- atf_amc.TypeBE32en.value.SetStrptrMaybe
15596// Convert string to field.
15597// If the string is invalid, do not modify field and return false.
15598// In case of success, return true
15599bool atf_amc::value_SetStrptrMaybe(atf_amc::TypeBE32en& parent, algo::strptr rhs) {
15600 bool ret = false;
15601 switch (elems_N(rhs)) {
15602 case 4: {
15603 switch (u64(algo::ReadLE32(rhs.elems))) {
15604 case LE_STR4('v','a','l','1'): {
15605 value_SetEnum(parent,atf_amc_TypeBE32en_value_val1); ret = true; break;
15606 }
15607 case LE_STR4('v','a','l','2'): {
15608 value_SetEnum(parent,atf_amc_TypeBE32en_value_val2); ret = true; break;
15609 }
15610 }
15611 break;
15612 }
15613 }
15614 return ret;
15615}
15616
15617// --- atf_amc.TypeBE32en.value.SetStrptr
15618// Convert string to field.
15619// If the string is invalid, set numeric value to DFLT
15620void atf_amc::value_SetStrptr(atf_amc::TypeBE32en& parent, algo::strptr rhs, atf_amc_TypeBE32en_value_Enum dflt) {
15621 if (!value_SetStrptrMaybe(parent,rhs)) value_SetEnum(parent,dflt);
15622}
15623
15624// --- atf_amc.TypeBE32en.value.ReadStrptrMaybe
15625// Convert string to field. Return success value
15626bool atf_amc::value_ReadStrptrMaybe(atf_amc::TypeBE32en& parent, algo::strptr rhs) {
15627 bool retval = false;
15628 retval = value_SetStrptrMaybe(parent,rhs); // try symbol conversion
15629 if (!retval) { // didn't work? try reading as underlying type
15630 u32 value_tmp;
15631 retval = u32_ReadStrptrMaybe(value_tmp, rhs);
15632 if (retval) {
15633 value_Set(parent, value_tmp);
15634 }
15635 }
15636 return retval;
15637}
15638
15639// --- atf_amc.TypeBE32en..ReadFieldMaybe
15640bool atf_amc::TypeBE32en_ReadFieldMaybe(atf_amc::TypeBE32en& parent, algo::strptr field, algo::strptr strval) {
15641 bool retval = true;
15642 atf_amc::FieldId field_id;
15643 (void)value_SetStrptrMaybe(field_id,field);
15644 switch(field_id) {
15645 case atf_amc_FieldId_value: {
15646 retval = value_ReadStrptrMaybe(parent, strval);
15647 break;
15648 }
15649 default: break;
15650 }
15651 if (!retval) {
15652 algo_lib::AppendErrtext("attr",field);
15653 }
15654 return retval;
15655}
15656
15657// --- atf_amc.TypeBE32en..ReadStrptrMaybe
15658// Read fields of atf_amc::TypeBE32en from an ascii string.
15659// The format of the string is the format of the atf_amc::TypeBE32en's only field
15660bool atf_amc::TypeBE32en_ReadStrptrMaybe(atf_amc::TypeBE32en &parent, algo::strptr in_str) {
15661 bool retval = true;
15662 retval = retval && value_ReadStrptrMaybe(parent, in_str);
15663 return retval;
15664}
15665
15666// --- atf_amc.TypeBE32en..ReadTupleMaybe
15667// Read fields of atf_amc::TypeBE32en from attributes of ascii tuple TUPLE
15668bool atf_amc::TypeBE32en_ReadTupleMaybe(atf_amc::TypeBE32en &parent, algo::Tuple &tuple) {
15669 bool retval = true;
15670 ind_beg(algo::Tuple_attrs_curs,attr,tuple) {
15671 retval = TypeBE32en_ReadFieldMaybe(parent, attr.name, attr.value);
15672 if (!retval) {
15673 break;
15674 }
15675 }ind_end;
15676 return retval;
15677}
15678
15679// --- atf_amc.TypeBE32en..Print
15680// print string representation of ROW to string STR
15681// cfmt:atf_amc.TypeBE32en.String printfmt:Raw
15682void atf_amc::TypeBE32en_Print(atf_amc::TypeBE32en& row, algo::cstring& str) {
15683 atf_amc::value_Print(row, str);
15684}
15685
15686// --- atf_amc.TypeBE64.value.ReadStrptrMaybe
15687inline static bool atf_amc::value_ReadStrptrMaybe(atf_amc::TypeBE64 &parent, algo::strptr in_str) {
15688 bool retval = true;
15689 u64 value_tmp;
15690 retval = u64_ReadStrptrMaybe(value_tmp, in_str);
15691 if (retval) {
15692 value_Set(parent, value_tmp);
15693 }
15694 return retval;
15695}
15696
15697// --- atf_amc.TypeBE64..ReadFieldMaybe
15698bool atf_amc::TypeBE64_ReadFieldMaybe(atf_amc::TypeBE64& parent, algo::strptr field, algo::strptr strval) {
15699 bool retval = true;
15700 atf_amc::FieldId field_id;
15701 (void)value_SetStrptrMaybe(field_id,field);
15702 switch(field_id) {
15703 case atf_amc_FieldId_value: {
15704 retval = value_ReadStrptrMaybe(parent, strval);
15705 break;
15706 }
15707 default: break;
15708 }
15709 if (!retval) {
15710 algo_lib::AppendErrtext("attr",field);
15711 }
15712 return retval;
15713}
15714
15715// --- atf_amc.TypeBE64..ReadStrptrMaybe
15716// Read fields of atf_amc::TypeBE64 from an ascii string.
15717// The format of the string is the format of the atf_amc::TypeBE64's only field
15718bool atf_amc::TypeBE64_ReadStrptrMaybe(atf_amc::TypeBE64 &parent, algo::strptr in_str) {
15719 bool retval = true;
15720 retval = retval && value_ReadStrptrMaybe(parent, in_str);
15721 return retval;
15722}
15723
15724// --- atf_amc.TypeBE64..ReadTupleMaybe
15725// Read fields of atf_amc::TypeBE64 from attributes of ascii tuple TUPLE
15726bool atf_amc::TypeBE64_ReadTupleMaybe(atf_amc::TypeBE64 &parent, algo::Tuple &tuple) {
15727 bool retval = true;
15728 ind_beg(algo::Tuple_attrs_curs,attr,tuple) {
15729 retval = TypeBE64_ReadFieldMaybe(parent, attr.name, attr.value);
15730 if (!retval) {
15731 break;
15732 }
15733 }ind_end;
15734 return retval;
15735}
15736
15737// --- atf_amc.TypeBE64..Print
15738// print string representation of ROW to string STR
15739// cfmt:atf_amc.TypeBE64.String printfmt:Raw
15740void atf_amc::TypeBE64_Print(atf_amc::TypeBE64& row, algo::cstring& str) {
15741 u64_Print(value_Get(row), str);
15742}
15743
15744// --- atf_amc.TypeC..ReadStrptrMaybe
15745// Read fields of atf_amc::TypeC from an ascii string.
15746// The format of the string is the format of the atf_amc::TypeC's only field
15747bool atf_amc::TypeC_ReadStrptrMaybe(atf_amc::TypeC &parent, algo::strptr in_str) {
15748 bool retval = true;
15749 retval = retval && i32_ReadStrptrMaybe(parent.typec, in_str);
15750 return retval;
15751}
15752
15753// --- atf_amc.TypeC..Print
15754// print string representation of ROW to string STR
15755// cfmt:atf_amc.TypeC.String printfmt:Raw
15756void atf_amc::TypeC_Print(atf_amc::TypeC& row, algo::cstring& str) {
15757 i32_Print(row.typec, str);
15758}
15759
15760// --- atf_amc.TypeH..ReadStrptrMaybe
15761// Read fields of atf_amc::TypeH from an ascii string.
15762// The format of the string is the format of the atf_amc::TypeH's only field
15763bool atf_amc::TypeH_ReadStrptrMaybe(atf_amc::TypeH &parent, algo::strptr in_str) {
15764 bool retval = true;
15765 retval = retval && i32_ReadStrptrMaybe(parent.typeh, in_str);
15766 return retval;
15767}
15768
15769// --- atf_amc.TypeH..Print
15770// print string representation of ROW to string STR
15771// cfmt:atf_amc.TypeH.String printfmt:Raw
15772void atf_amc::TypeH_Print(atf_amc::TypeH& row, algo::cstring& str) {
15773 i32_Print(row.typeh, str);
15774}
15775
15776// --- atf_amc.TypeS..ReadFieldMaybe
15777bool atf_amc::TypeS_ReadFieldMaybe(atf_amc::TypeS& parent, algo::strptr field, algo::strptr strval) {
15778 bool retval = true;
15779 atf_amc::FieldId field_id;
15780 (void)value_SetStrptrMaybe(field_id,field);
15781 switch(field_id) {
15782 case atf_amc_FieldId_types: {
15783 retval = i32_ReadStrptrMaybe(parent.types, strval);
15784 break;
15785 }
15786 case atf_amc_FieldId_comment: {
15787 retval = algo::Comment_ReadStrptrMaybe(parent.comment, strval);
15788 break;
15789 }
15790 default: break;
15791 }
15792 if (!retval) {
15793 algo_lib::AppendErrtext("attr",field);
15794 }
15795 return retval;
15796}
15797
15798// --- atf_amc.TypeS..ReadStrptrMaybe
15799// Read fields of atf_amc::TypeS from an ascii string.
15800// The format of the string is an ssim Tuple
15801bool atf_amc::TypeS_ReadStrptrMaybe(atf_amc::TypeS &parent, algo::strptr in_str) {
15802 bool retval = true;
15803 retval = algo::StripTypeTag(in_str, "atf_amc.TypeS");
15804 ind_beg(algo::Attr_curs, attr, in_str) {
15805 retval = retval && TypeS_ReadFieldMaybe(parent, attr.name, attr.value);
15806 }ind_end;
15807 return retval;
15808}
15809
15810// --- atf_amc.TypeS..Print
15811// print string representation of ROW to string STR
15812// cfmt:atf_amc.TypeS.String printfmt:Tuple
15813void atf_amc::TypeS_Print(atf_amc::TypeS& row, algo::cstring& str) {
15814 algo::tempstr temp;
15815 str << "atf_amc.TypeS";
15816
15817 i32_Print(row.types, temp);
15818 PrintAttrSpaceReset(str,"types", temp);
15819
15820 algo::Comment_Print(row.comment, temp);
15821 PrintAttrSpaceReset(str,"comment", temp);
15822}
15823
15824// --- atf_amc.TypeT..ReadFieldMaybe
15825bool atf_amc::TypeT_ReadFieldMaybe(atf_amc::TypeT& parent, algo::strptr field, algo::strptr strval) {
15826 bool retval = true;
15827 atf_amc::FieldId field_id;
15828 (void)value_SetStrptrMaybe(field_id,field);
15829 switch(field_id) {
15830 case atf_amc_FieldId_types: {
15831 retval = i32_ReadStrptrMaybe(parent.types, strval);
15832 break;
15833 }
15834 case atf_amc_FieldId_j: {
15835 retval = i32_ReadStrptrMaybe(parent.j, strval);
15836 break;
15837 }
15838 default: break;
15839 }
15840 if (!retval) {
15841 algo_lib::AppendErrtext("attr",field);
15842 }
15843 return retval;
15844}
15845
15846// --- atf_amc.TypeT..ReadStrptrMaybe
15847// Read fields of atf_amc::TypeT from an ascii string.
15848// The format of the string is an ssim Tuple
15849bool atf_amc::TypeT_ReadStrptrMaybe(atf_amc::TypeT &parent, algo::strptr in_str) {
15850 bool retval = true;
15851 retval = algo::StripTypeTag(in_str, "atf_amc.TypeT");
15852 ind_beg(algo::Attr_curs, attr, in_str) {
15853 retval = retval && TypeT_ReadFieldMaybe(parent, attr.name, attr.value);
15854 }ind_end;
15855 return retval;
15856}
15857
15858// --- atf_amc.TypeT..Print
15859// print string representation of ROW to string STR
15860// cfmt:atf_amc.TypeT.String printfmt:Tuple
15861void atf_amc::TypeT_Print(atf_amc::TypeT& row, algo::cstring& str) {
15862 algo::tempstr temp;
15863 str << "atf_amc.TypeT";
15864
15865 i32_Print(row.types, temp);
15866 PrintAttrSpaceReset(str,"types", temp);
15867
15868 i32_Print(row.j, temp);
15869 PrintAttrSpaceReset(str,"j", temp);
15870}
15871
15872// --- atf_amc.TypeTVal..ReadFieldMaybe
15873bool atf_amc::TypeTVal_ReadFieldMaybe(atf_amc::TypeTVal& parent, algo::strptr field, algo::strptr strval) {
15874 bool retval = true;
15875 atf_amc::FieldId field_id;
15876 (void)value_SetStrptrMaybe(field_id,field);
15877 switch(field_id) {
15878 case atf_amc_FieldId_types: {
15879 retval = atf_amc::TypeS_ReadStrptrMaybe(parent.types, strval);
15880 break;
15881 }
15882 case atf_amc_FieldId_j: {
15883 retval = i32_ReadStrptrMaybe(parent.j, strval);
15884 break;
15885 }
15886 default: break;
15887 }
15888 if (!retval) {
15889 algo_lib::AppendErrtext("attr",field);
15890 }
15891 return retval;
15892}
15893
15894// --- atf_amc.TypeTVal..ReadStrptrMaybe
15895// Read fields of atf_amc::TypeTVal from an ascii string.
15896// The format of the string is an ssim Tuple
15897bool atf_amc::TypeTVal_ReadStrptrMaybe(atf_amc::TypeTVal &parent, algo::strptr in_str) {
15898 bool retval = true;
15899 retval = algo::StripTypeTag(in_str, "atf_amc.TypeTVal");
15900 ind_beg(algo::Attr_curs, attr, in_str) {
15901 retval = retval && TypeTVal_ReadFieldMaybe(parent, attr.name, attr.value);
15902 }ind_end;
15903 return retval;
15904}
15905
15906// --- atf_amc.TypeTVal..Print
15907// print string representation of ROW to string STR
15908// cfmt:atf_amc.TypeTVal.String printfmt:Tuple
15909void atf_amc::TypeTVal_Print(atf_amc::TypeTVal& row, algo::cstring& str) {
15910 algo::tempstr temp;
15911 str << "atf_amc.TypeTVal";
15912
15913 atf_amc::TypeS_Print(row.types, temp);
15914 PrintAttrSpaceReset(str,"types", temp);
15915
15916 i32_Print(row.j, temp);
15917 PrintAttrSpaceReset(str,"j", temp);
15918}
15919
15920// --- atf_amc.Typefconst.value.ToCstr
15921// Convert numeric value of field to one of predefined string constants.
15922// If string is found, return a static C string. Otherwise, return NULL.
15923const char* atf_amc::value_ToCstr(const atf_amc::Typefconst& parent) {
15924 const char *ret = NULL;
15925 switch(value_GetEnum(parent)) {
15926 case atf_amc_Typefconst_value_strval1: ret = "strval1"; break;
15927 case atf_amc_Typefconst_value_strval2: ret = "strval2"; break;
15928 }
15929 return ret;
15930}
15931
15932// --- atf_amc.Typefconst.value.Print
15933// Convert value to a string. First, attempt conversion to a known string.
15934// If no string matches, print value as a numeric value.
15935void atf_amc::value_Print(const atf_amc::Typefconst& parent, algo::cstring &lhs) {
15936 const char *strval = value_ToCstr(parent);
15937 if (strval) {
15938 lhs << strval;
15939 } else {
15940 lhs << parent.value;
15941 }
15942}
15943
15944// --- atf_amc.Typefconst.value.SetStrptrMaybe
15945// Convert string to field.
15946// If the string is invalid, do not modify field and return false.
15947// In case of success, return true
15948bool atf_amc::value_SetStrptrMaybe(atf_amc::Typefconst& parent, algo::strptr rhs) {
15949 bool ret = false;
15950 switch (elems_N(rhs)) {
15951 case 7: {
15952 switch (u64(algo::ReadLE32(rhs.elems))|(u64(algo::ReadLE16(rhs.elems+4))<<32)|(u64(rhs[6])<<48)) {
15953 case LE_STR7('s','t','r','v','a','l','1'): {
15954 value_SetEnum(parent,atf_amc_Typefconst_value_strval1); ret = true; break;
15955 }
15956 case LE_STR7('s','t','r','v','a','l','2'): {
15957 value_SetEnum(parent,atf_amc_Typefconst_value_strval2); ret = true; break;
15958 }
15959 }
15960 break;
15961 }
15962 }
15963 return ret;
15964}
15965
15966// --- atf_amc.Typefconst.value.SetStrptr
15967// Convert string to field.
15968// If the string is invalid, set numeric value to DFLT
15969void atf_amc::value_SetStrptr(atf_amc::Typefconst& parent, algo::strptr rhs, atf_amc_Typefconst_value_Enum dflt) {
15970 if (!value_SetStrptrMaybe(parent,rhs)) value_SetEnum(parent,dflt);
15971}
15972
15973// --- atf_amc.Typefconst.value.ReadStrptrMaybe
15974// Convert string to field. Return success value
15975bool atf_amc::value_ReadStrptrMaybe(atf_amc::Typefconst& parent, algo::strptr rhs) {
15976 bool retval = false;
15977 retval = value_SetStrptrMaybe(parent,rhs); // try symbol conversion
15978 if (!retval) { // didn't work? try reading as underlying type
15979 retval = u32_ReadStrptrMaybe(parent.value,rhs);
15980 }
15981 return retval;
15982}
15983
15984// --- atf_amc.Typefconst..ReadFieldMaybe
15985bool atf_amc::Typefconst_ReadFieldMaybe(atf_amc::Typefconst& parent, algo::strptr field, algo::strptr strval) {
15986 bool retval = true;
15987 atf_amc::FieldId field_id;
15988 (void)value_SetStrptrMaybe(field_id,field);
15989 switch(field_id) {
15990 case atf_amc_FieldId_value: {
15991 retval = value_ReadStrptrMaybe(parent, strval);
15992 break;
15993 }
15994 default: break;
15995 }
15996 if (!retval) {
15997 algo_lib::AppendErrtext("attr",field);
15998 }
15999 return retval;
16000}
16001
16002// --- atf_amc.Typefconst..ReadStrptrMaybe
16003// Read fields of atf_amc::Typefconst from an ascii string.
16004// The format of the string is the format of the atf_amc::Typefconst's only field
16005bool atf_amc::Typefconst_ReadStrptrMaybe(atf_amc::Typefconst &parent, algo::strptr in_str) {
16006 bool retval = true;
16007 retval = retval && value_ReadStrptrMaybe(parent, in_str);
16008 return retval;
16009}
16010
16011// --- atf_amc.Typefconst..ReadTupleMaybe
16012// Read fields of atf_amc::Typefconst from attributes of ascii tuple TUPLE
16013bool atf_amc::Typefconst_ReadTupleMaybe(atf_amc::Typefconst &parent, algo::Tuple &tuple) {
16014 bool retval = true;
16015 ind_beg(algo::Tuple_attrs_curs,attr,tuple) {
16016 retval = Typefconst_ReadFieldMaybe(parent, attr.name, attr.value);
16017 if (!retval) {
16018 break;
16019 }
16020 }ind_end;
16021 return retval;
16022}
16023
16024// --- atf_amc.Typefconst..Print
16025// print string representation of ROW to string STR
16026// cfmt:atf_amc.Typefconst.String printfmt:Raw
16027void atf_amc::Typefconst_Print(atf_amc::Typefconst& row, algo::cstring& str) {
16028 atf_amc::value_Print(row, str);
16029}
16030
16031// --- atf_amc.VarlenAlloc.elem.Getary
16032// Access var-length portion as an aryptr. Length is determined from one of the fields.
16033algo::aryptr<i32> atf_amc::elem_Getary(atf_amc::VarlenAlloc& varlenalloc) {
16034 return algo::aryptr<i32>(elem_Addr(varlenalloc), elem_N(varlenalloc));
16035}
16036
16037// --- atf_amc.VarlenAlloc.elem.Addr
16038i32* atf_amc::elem_Addr(atf_amc::VarlenAlloc& varlenalloc) {
16039 return (i32*)((u8*)&varlenalloc + sizeof(atf_amc::VarlenAlloc)); // address of varlen portion
16040}
16041
16042// --- atf_amc.VarlenExtern.varlen.Getary
16043// Access var-length portion as an aryptr. Length is determined from one of the fields.
16044algo::aryptr<u32> atf_amc::varlen_Getary(atf_amc::VarlenExtern& varlen_extern) {
16045 return algo::aryptr<u32>(varlen_Addr(varlen_extern), varlen_N(varlen_extern));
16046}
16047
16048// --- atf_amc.VarlenExtern.varlen.Addr
16049u32* atf_amc::varlen_Addr(atf_amc::VarlenExtern& varlen_extern) {
16050 return (u32*)((u8*)&varlen_extern + sizeof(atf_amc::VarlenExtern)); // address of varlen portion
16051}
16052
16053// --- atf_amc.VarlenH.typeh.Getary
16054// Access var-length portion as an aryptr. Length is determined from one of the fields.
16055algo::aryptr<atf_amc::TypeH> atf_amc::typeh_Getary(atf_amc::VarlenH& parent) {
16056 return algo::aryptr<atf_amc::TypeH>(typeh_Addr(parent), typeh_N(parent));
16057}
16058
16059// --- atf_amc.VarlenH.typeh.Addr
16060atf_amc::TypeH* atf_amc::typeh_Addr(atf_amc::VarlenH& parent) {
16061 return (atf_amc::TypeH*)((u8*)&parent + sizeof(atf_amc::VarlenH)); // address of varlen portion
16062}
16063
16064// --- atf_amc.VarlenH.typeh.Swap
16065// Swap values elem_a and elem_b
16066inline static void atf_amc::typeh_Swap(atf_amc::TypeH &elem_a, atf_amc::TypeH &elem_b) {
16067 u8 temp[sizeof(atf_amc::TypeH)];
16068 memcpy(&temp , &elem_a, sizeof(atf_amc::TypeH));
16069 memcpy(&elem_a, &elem_b, sizeof(atf_amc::TypeH));
16070 memcpy(&elem_b, &temp , sizeof(atf_amc::TypeH));
16071}
16072
16073// --- atf_amc.VarlenH.typeh.Rotleft
16074// Left circular shift of three-tuple
16075inline static void atf_amc::typeh_Rotleft(atf_amc::TypeH &elem_a, atf_amc::TypeH &elem_b, atf_amc::TypeH &elem_c) {
16076 u8 temp[sizeof(atf_amc::TypeH)];
16077 memcpy(&temp, &elem_a , sizeof(atf_amc::TypeH));
16078 memcpy(&elem_a , &elem_b , sizeof(atf_amc::TypeH));
16079 memcpy(&elem_b , &elem_c , sizeof(atf_amc::TypeH));
16080 memcpy(&elem_c , &temp, sizeof(atf_amc::TypeH));
16081}
16082
16083// --- atf_amc.VarlenH.typeh.Lt
16084// Compare values elem_a and elem_b
16085// The comparison function must be anti-symmetric: if a>b, then !(b>a).
16086// If not, mayhem results.
16087static bool atf_amc::typeh_Lt(atf_amc::TypeH &elem_a, atf_amc::TypeH &elem_b) {
16088 bool ret;
16089 ret = elem_a.typeh < elem_b.typeh;
16090 return ret;
16091}
16092
16093// --- atf_amc.VarlenH.typeh.SortedQ
16094// Verify whether array is sorted
16095bool atf_amc::typeh_SortedQ(atf_amc::VarlenH& parent) {
16096 atf_amc::TypeH *elems = typeh_Getary(parent).elems;
16097 int n = typeh_N(parent);
16098 for (int i = 1; i < n; i++) {
16099 if (typeh_Lt(elems[i], elems[i-1])) {
16100 return false;
16101 }
16102 }
16103 return true;
16104}
16105
16106// --- atf_amc.VarlenH.typeh.IntInsertionSort
16107// Internal insertion sort
16108static void atf_amc::typeh_IntInsertionSort(atf_amc::TypeH *elems, int n) {
16109 for (int i = 1; i < n; ++i) {
16110 int j = i;
16111 // find the spot for ith element.
16112 while (j>0 && typeh_Lt(elems[i], elems[j-1])) {
16113 j--;
16114 }
16115 if (j<i) {
16116 u8 tmp[sizeof(atf_amc::TypeH)];
16117 memcpy (tmp , &elems[i], sizeof(atf_amc::TypeH) );
16118 memmove(&elems[j+1], &elems[j], sizeof(atf_amc::TypeH)*(i-j));
16119 memcpy (&elems[j] , tmp , sizeof(atf_amc::TypeH) );
16120 }
16121 }
16122}
16123
16124// --- atf_amc.VarlenH.typeh.IntHeapSort
16125// Internal heap sort
16126static void atf_amc::typeh_IntHeapSort(atf_amc::TypeH *elems, int n) {
16127 // construct max-heap.
16128 // k=current element
16129 // j=parent element
16130 for (int i = 1; i < n; i++) {
16131 int k=i;
16132 int j=(i-1)/2;
16133 while (typeh_Lt(elems[j], elems[k])) {
16134 typeh_Swap(elems[k],elems[j]);
16135 k=j;
16136 j=(k-1)/2;
16137 }
16138 }
16139 // remove elements from heap one-by-one,
16140 // deposit them in reverse order starting at the end of ARY.
16141 for (int i = n - 1; i>=0; i--) {
16142 int k = 0;
16143 int l = 1;
16144 while (l<i) {
16145 l += l<i-1 && typeh_Lt(elems[l], elems[l+1]);
16146 if (typeh_Lt(elems[l], elems[i])) {
16147 break;
16148 }
16149 typeh_Swap(elems[k], elems[l]);
16150 k = l;
16151 l = k*2+1;
16152 }
16153 if (i != k) {
16154 typeh_Swap(elems[i],elems[k]);
16155 }
16156 }
16157}
16158
16159// --- atf_amc.VarlenH.typeh.IntQuickSort
16160// Quick sort engine
16161static void atf_amc::typeh_IntQuickSort(atf_amc::TypeH *elems, int n, int depth) {
16162 while (n>16) {
16163 // detect degenerate case and revert to heap sort
16164 if (depth==0) {
16165 typeh_IntHeapSort(elems,n);
16166 return;
16167 }
16168 // elements to sort initially to determine pivot.
16169 // choose pp=n/2 in case the input is already sorted.
16170 int pi = 0;
16171 int pp = n/2;
16172 int pj = n-1;
16173 // insertion sort for 1st, middle and last element
16174 if (typeh_Lt(elems[pp], elems[pi])) {
16175 typeh_Swap(elems[pi], elems[pp]);
16176 }
16177 if (typeh_Lt(elems[pj], elems[pp])) {
16178 if (typeh_Lt(elems[pj], elems[pi])) {
16179 typeh_Rotleft(elems[pi], elems[pj], elems[pp]);
16180 } else {
16181 typeh_Swap(elems[pj], elems[pp]);
16182 }
16183 }
16184 // deposit pivot near the end of the array and skip it.
16185 typeh_Swap(elems[--pj], elems[pp]);
16186 // reference to pivot
16187 atf_amc::TypeH &pivot = elems[pj];
16188 for(;;){
16189 while (typeh_Lt(elems[++pi], pivot)) {
16190 }
16191 while (typeh_Lt(pivot, elems[--pj])) {
16192 }
16193 if (pj <= pi) {
16194 break;
16195 }
16196 typeh_Swap(elems[pi],elems[pj]);
16197 }
16198 depth -= 1;
16199 typeh_IntQuickSort(elems, pi, depth);
16200 elems += pi;
16201 n -= pi;
16202 }
16203 // sort the remainder of this section
16204 typeh_IntInsertionSort(elems,n);
16205}
16206
16207// --- atf_amc.VarlenH.typeh.InsertionSort
16208// Insertion sort
16209void atf_amc::typeh_InsertionSort(atf_amc::VarlenH& parent) {
16210 atf_amc::TypeH *elems = typeh_Getary(parent).elems;
16211 int n = typeh_N(parent);
16212 typeh_IntInsertionSort(elems, n);
16213}
16214
16215// --- atf_amc.VarlenH.typeh.HeapSort
16216// Heap sort
16217void atf_amc::typeh_HeapSort(atf_amc::VarlenH& parent) {
16218 atf_amc::TypeH *elems = typeh_Getary(parent).elems;
16219 int n = typeh_N(parent);
16220 typeh_IntHeapSort(elems, n);
16221}
16222
16223// --- atf_amc.VarlenH.typeh.QuickSort
16224// Quick sort
16225void atf_amc::typeh_QuickSort(atf_amc::VarlenH& parent) {
16226 // compute max recursion depth based on number of elements in the array
16227 int max_depth = algo::CeilingLog2(u32(typeh_N(parent) + 1)) + 3;
16228 atf_amc::TypeH *elems = typeh_Getary(parent).elems;
16229 int n = typeh_N(parent);
16230 typeh_IntQuickSort(elems, n, max_depth);
16231}
16232
16233// --- atf_amc.VarlenH.typeh.XrefMaybe
16234// Insert row into all appropriate indices. If error occurs, store error
16235// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
16236bool atf_amc::typeh_XrefMaybe(atf_amc::TypeH &row) {
16237 bool retval = true;
16238 (void)row;
16239 return retval;
16240}
16241
16242// --- atf_amc.VarlenK.i.Getary
16243// Access var-length portion as an aryptr. Length is determined from one of the fields.
16244algo::aryptr<u32> atf_amc::i_Getary(atf_amc::VarlenK& k) {
16245 return algo::aryptr<u32>(i_Addr(k), i_N(k));
16246}
16247
16248// --- atf_amc.VarlenK.i.Addr
16249u32* atf_amc::i_Addr(atf_amc::VarlenK& k) {
16250 return (u32*)((u8*)&k + sizeof(atf_amc::VarlenK)); // address of varlen portion
16251}
16252
16253// --- atf_amc.VarlenK.i.ReadStrptrMaybe
16254// Convert string to field. Return success value
16255bool atf_amc::i_ReadStrptrMaybe(atf_amc::VarlenK& k, algo::strptr in_str) {
16256 bool retval = true;
16257 if (algo_lib::_db.varlenbuf) {
16258 u32 *i_tmp = new(ary_AllocN(*algo_lib::_db.varlenbuf, sizeof(u32)).elems) u32;
16259 retval = u32_ReadStrptrMaybe(*i_tmp, in_str);
16260 }
16261 (void)k;//only to avoid -Wunused-parameter
16262 return retval;
16263}
16264
16265// --- atf_amc.VarlenK..ReadFieldMaybe
16266bool atf_amc::VarlenK_ReadFieldMaybe(atf_amc::VarlenK& parent, algo::strptr field, algo::strptr strval) {
16267 bool retval = true;
16268 atf_amc::FieldId field_id;
16269 (void)value_SetStrptrMaybe(field_id,algo::Pathcomp(field, ".LL"));
16270 switch(field_id) {
16271 case atf_amc_FieldId_length: {
16272 retval = false;
16273 break;
16274 }
16275 case atf_amc_FieldId_i: {
16276 retval = i_ReadStrptrMaybe(parent, strval);
16277 break;
16278 }
16279 default: break;
16280 }
16281 if (!retval) {
16282 algo_lib::AppendErrtext("attr",field);
16283 }
16284 return retval;
16285}
16286
16287// --- atf_amc.VarlenK..ReadStrptrMaybe
16288// Any varlen fields are returned in algo_lib::_db.varlenbuf if set
16289// Read fields of atf_amc::VarlenK from an ascii string.
16290// The format of the string is an ssim Tuple
16291bool atf_amc::VarlenK_ReadStrptrMaybe(atf_amc::VarlenK &parent, algo::strptr in_str) {
16292 bool retval = true;
16293 retval = algo::StripTypeTag(in_str, "atf_amc.VarlenK");
16294 ind_beg(algo::Attr_curs, attr, in_str) {
16295 retval = retval && VarlenK_ReadFieldMaybe(parent, attr.name, attr.value);
16296 }ind_end;
16297 return retval;
16298}
16299
16300// --- atf_amc.VarlenK..Print
16301// print string representation of ROW to string STR
16302// cfmt:atf_amc.VarlenK.String printfmt:Tuple
16303void atf_amc::VarlenK_Print(atf_amc::VarlenK& row, algo::cstring& str) {
16304 algo::tempstr temp;
16305 str << "atf_amc.VarlenK";
16306
16307 ind_beg(k_i_curs,i,row) {
16308 u32_Print(i, temp);
16309 tempstr name;
16310 name << "i.";
16311 name << ind_curs(i).index;
16312 PrintAttrSpaceReset(str, name, temp);
16313 }ind_end;
16314}
16315
16316// --- atf_amc.VarlenMsg.base.CopyOut
16317// Copy fields out of row
16318void atf_amc::parent_CopyOut(atf_amc::VarlenMsg &row, atf_amc::MsgHeader &out) {
16319 // type: field value is computed
16320 // length: field value is computed
16321 (void)row;//only to avoid -Wunused-parameter
16322 (void)out;//only to avoid -Wunused-parameter
16323}
16324
16325// --- atf_amc.VarlenMsg.k.Getary
16326// Access var-length portion as an aryptr. Length is determined from one of the fields.
16327algo::aryptr<u8> atf_amc::k_Getary(atf_amc::VarlenMsg& parent) {
16328 return algo::aryptr<u8>(k_Addr(parent), k_N(parent));
16329}
16330
16331// --- atf_amc.VarlenMsg.k.Addr
16332u8* atf_amc::k_Addr(atf_amc::VarlenMsg& parent) {
16333 return (u8*)((u8*)&parent + sizeof(atf_amc::VarlenMsg)); // address of varlen portion
16334}
16335
16336// --- atf_amc.VarlenMsg.k.ReadStrptrMaybe
16337// Convert string to field. Return success value
16338bool atf_amc::k_ReadStrptrMaybe(atf_amc::VarlenMsg& parent, algo::strptr in_str) {
16339 bool retval = true;
16340 if (algo_lib::_db.varlenbuf) {
16341 atf_amc::VarlenK *k_tmp = new(ary_AllocN(*algo_lib::_db.varlenbuf, sizeof(atf_amc::VarlenK)).elems) atf_amc::VarlenK;
16342 retval = atf_amc::VarlenK_ReadStrptrMaybe(*k_tmp, in_str);
16343 }
16344 (void)parent;//only to avoid -Wunused-parameter
16345 return retval;
16346}
16347
16348// --- atf_amc.VarlenMsg.k.XrefMaybe
16349// Insert row into all appropriate indices. If error occurs, store error
16350// in algo_lib::_db.errtext and return false. Caller must Delete or Unref such row.
16351bool atf_amc::k_XrefMaybe(atf_amc::VarlenK &row) {
16352 bool retval = true;
16353 (void)row;
16354 return retval;
16355}
16356
16357// --- atf_amc.VarlenMsg..ReadFieldMaybe
16358bool atf_amc::VarlenMsg_ReadFieldMaybe(atf_amc::VarlenMsg& parent, algo::strptr field, algo::strptr strval) {
16359 bool retval = true;
16360 atf_amc::FieldId field_id;
16361 (void)value_SetStrptrMaybe(field_id,algo::Pathcomp(field, ".LL"));
16362 switch(field_id) {
16363 case atf_amc_FieldId_base: {
16364 retval = false;
16365 break;
16366 }
16367 case atf_amc_FieldId_type: {
16368 retval = false;
16369 break;
16370 }
16371 case atf_amc_FieldId_length: {
16372 retval = false;
16373 break;
16374 }
16375 case atf_amc_FieldId_k: {
16376 retval = k_ReadStrptrMaybe(parent, strval);
16377 break;
16378 }
16379 default: break;
16380 }
16381 if (!retval) {
16382 algo_lib::AppendErrtext("attr",field);
16383 }
16384 return retval;
16385}
16386
16387// --- atf_amc.VarlenMsg..ReadStrptrMaybe
16388// Any varlen fields are returned in algo_lib::_db.varlenbuf if set
16389// Read fields of atf_amc::VarlenMsg from an ascii string.
16390// The format of the string is an ssim Tuple
16391bool atf_amc::VarlenMsg_ReadStrptrMaybe(atf_amc::VarlenMsg &parent, algo::strptr in_str) {
16392 bool retval = true;
16393 retval = algo::StripTypeTag(in_str, "atf_amc.VarlenMsg");
16394 ind_beg(algo::Attr_curs, attr, in_str) {
16395 retval = retval && VarlenMsg_ReadFieldMaybe(parent, attr.name, attr.value);
16396 }ind_end;
16397 return retval;
16398}
16399
16400// --- atf_amc.VarlenMsg..Print
16401// print string representation of ROW to string STR
16402// cfmt:atf_amc.VarlenMsg.String printfmt:Tuple
16403void atf_amc::VarlenMsg_Print(atf_amc::VarlenMsg& row, algo::cstring& str) {
16404 algo::tempstr temp;
16405 str << "atf_amc.VarlenMsg";
16406
16407 ind_beg(VarlenMsg_k_curs,k,row) {
16408 atf_amc::VarlenK_Print(k, temp);
16409 tempstr name;
16410 name << "k.";
16411 name << ind_curs(k).index;
16412 PrintAttrSpaceReset(str, name, temp);
16413 }ind_end;
16414}
16415
16416// --- atf_amc...ForAllStrings
16417// Test string conversion
16418void atf_amc::ForAllStrings(void (*fcn)(algo::StringDesc&) ) {
16419 algo::StringDesc desc;
16420 // fill out descriptor for numstr:atf_amc.RnullStr6_U32.ch
16421 {
16422 desc.Geti64 = Geti64Fcn(static_cast<i64(*)(atf_amc::RnullStr6_U32&,bool&)>(ch_Geti64));
16423 desc.SetnumMaybe = SetnumFcn(static_cast<bool(*)(atf_amc::RnullStr6_U32&,i64)>(ch_SetnumMaybe));
16424 desc.Init = InitFcn(static_cast<void(*)(atf_amc::RnullStr6_U32&)>(ch_Init));
16425 desc.Getary = GetaryFcn(static_cast<algo::aryptr<char>(*)(const atf_amc::RnullStr6_U32&)>(ch_Getary));
16426 desc.smallstr = "atf_amc.RnullStr6_U32.ch";
16427 desc.strtype = "rightpad";
16428 desc.pad = 0;
16429 desc.base = 10;
16430 desc.issigned = false;
16431 desc.min_length = 1;
16432 desc.max_length = 6;
16433 desc.numtype_max = 0XFFFFFFFF;
16434 desc.numtype_min = 0X0;
16435 fcn(desc); // call test function
16436 }
16437 // fill out descriptor for numstr:atf_amc.RpasU32Str6.ch
16438 {
16439 desc.Geti64 = Geti64Fcn(static_cast<i64(*)(atf_amc::RpasU32Str6&,bool&)>(ch_Geti64));
16440 desc.SetnumMaybe = SetnumFcn(static_cast<bool(*)(atf_amc::RpasU32Str6&,i64)>(ch_SetnumMaybe));
16441 desc.Init = InitFcn(static_cast<void(*)(atf_amc::RpasU32Str6&)>(ch_Init));
16442 desc.Getary = GetaryFcn(static_cast<algo::aryptr<char>(*)(const atf_amc::RpasU32Str6&)>(ch_Getary));
16443 desc.smallstr = "atf_amc.RpasU32Str6.ch";
16444 desc.strtype = "rpascal";
16445 desc.pad = 0;
16446 desc.base = 10;
16447 desc.issigned = false;
16448 desc.min_length = 1;
16449 desc.max_length = 6;
16450 desc.numtype_max = 0XFFFFFFFF;
16451 desc.numtype_min = 0X0;
16452 fcn(desc); // call test function
16453 }
16454}
16455
16456// --- atf_amc...SizeCheck
16457inline static void atf_amc::SizeCheck() {
16458}
16459
16460// --- atf_amc...StaticCheck
16461void atf_amc::StaticCheck() {
16462 algo_assert(sizeof(atf_amc::amctest_step_hook) == 8); // csize:atf_amc.amctest_step_hook
16463 algo_assert(sizeof(atf_amc::listtype_step_hook) == 8); // csize:atf_amc.listtype_step_hook
16464 algo_assert(sizeof(atf_amc::parent_callback_hook) == 8); // csize:atf_amc.parent_callback_hook
16465 // check that bitfield fits width
16466 algo_assert(sizeof(((atf_amc::BitfldType1*)0)->value)*8 >= 15);
16467 // check that bitfield fits width
16468 algo_assert(sizeof(((atf_amc::BitfldType2*)0)->value)*8 >= 2);
16469 // check that bitfield fits width
16470 algo_assert(sizeof(((atf_amc::BitfldU128*)0)->value)*8 >= 128);
16471 // check that bitfield fits width
16472 algo_assert(sizeof(((atf_amc::BitfldU16*)0)->value)*8 >= 12);
16473 algo_assert(_offset_of(atf_amc::DispCase, value) + sizeof(((atf_amc::DispCase*)0)->value) == sizeof(atf_amc::DispCase));
16474 algo_assert(_offset_of(atf_amc::trace, step_cd_in_msg_cycles) + sizeof(((atf_amc::trace*)0)->step_cd_in_msg_cycles) == sizeof(atf_amc::trace));
16475 algo_assert(_offset_of(atf_amc::FieldId, value) + sizeof(((atf_amc::FieldId*)0)->value) == sizeof(atf_amc::FieldId));
16476 algo_assert(_offset_of(atf_amc::MsgHdrLTMsgsCase, value) + sizeof(((atf_amc::MsgHdrLTMsgsCase*)0)->value) == sizeof(atf_amc::MsgHdrLTMsgsCase));
16477 algo_assert(_offset_of(atf_amc::MsgHdrLT_curs, msglen) + sizeof(((atf_amc::MsgHdrLT_curs*)0)->msglen) == sizeof(atf_amc::MsgHdrLT_curs));
16478 algo_assert(_offset_of(atf_amc::MsgType, value) + sizeof(((atf_amc::MsgType*)0)->value) == sizeof(atf_amc::MsgType));
16479 algo_assert(_offset_of(atf_amc::MsgLength, value) + sizeof(((atf_amc::MsgLength*)0)->value) == sizeof(atf_amc::MsgLength));
16480 algo_assert(_offset_of(atf_amc::MsgHeader, length) == 2);
16481 algo_assert(_offset_of(atf_amc::MsgHeader_curs, msglen) + sizeof(((atf_amc::MsgHeader_curs*)0)->msglen) == sizeof(atf_amc::MsgHeader_curs));
16482 algo_assert(_offset_of(atf_amc::MsgLTA, a) + sizeof(((atf_amc::MsgLTA*)0)->a) == sizeof(atf_amc::MsgLTA));
16483 algo_assert(_offset_of(atf_amc::MsgLTB, b) + sizeof(((atf_amc::MsgLTB*)0)->b) == sizeof(atf_amc::MsgLTB));
16484 algo_assert(_offset_of(atf_amc::MsgsCase, value) + sizeof(((atf_amc::MsgsCase*)0)->value) == sizeof(atf_amc::MsgsCase));
16485 // check that bitfield fits width
16486 algo_assert(sizeof(((atf_amc::NetBitfld1*)0)->value_be)*8 >= 12);
16487 algo_assert(_offset_of(atf_amc::OptAlloc_curs, msglen) + sizeof(((atf_amc::OptAlloc_curs*)0)->msglen) == sizeof(atf_amc::OptAlloc_curs));
16488 algo_assert(_offset_of(atf_amc::OptG_curs, msglen) + sizeof(((atf_amc::OptG_curs*)0)->msglen) == sizeof(atf_amc::OptG_curs));
16489 algo_assert(_offset_of(atf_amc::OptOptG_curs, msglen) + sizeof(((atf_amc::OptOptG_curs*)0)->msglen) == sizeof(atf_amc::OptOptG_curs));
16490 algo_assert(_offset_of(atf_amc::PmaskMultiple, value7) + sizeof(((atf_amc::PmaskMultiple*)0)->value7) == sizeof(atf_amc::PmaskMultiple));
16491 algo_assert(_offset_of(atf_amc::PmaskU128, value71) + sizeof(((atf_amc::PmaskU128*)0)->value71) == sizeof(atf_amc::PmaskU128));
16492 algo_assert(_offset_of(atf_amc::PmaskU32, value5) + sizeof(((atf_amc::PmaskU32*)0)->value5) == sizeof(atf_amc::PmaskU32));
16493 algo_assert(_offset_of(atf_amc::SsimfilesCase, value) + sizeof(((atf_amc::SsimfilesCase*)0)->value) == sizeof(atf_amc::SsimfilesCase));
16494 // check that bitfield fits width
16495 algo_assert(sizeof(((atf_amc::TypeBE64sf*)0)->value_be)*8 >= 64);
16496 algo_assert(_offset_of(atf_amc::VarlenAlloc_curs, msglen) + sizeof(((atf_amc::VarlenAlloc_curs*)0)->msglen) == sizeof(atf_amc::VarlenAlloc_curs));
16497 algo_assert(_offset_of(atf_amc::VarlenExtern_curs, msglen) + sizeof(((atf_amc::VarlenExtern_curs*)0)->msglen) == sizeof(atf_amc::VarlenExtern_curs));
16498 algo_assert(_offset_of(atf_amc::VarlenH_curs, msglen) + sizeof(((atf_amc::VarlenH_curs*)0)->msglen) == sizeof(atf_amc::VarlenH_curs));
16499 algo_assert(_offset_of(atf_amc::VarlenK_curs, msglen) + sizeof(((atf_amc::VarlenK_curs*)0)->msglen) == sizeof(atf_amc::VarlenK_curs));
16500}
16501
16502// --- atf_amc.MsgHdrLTMsgs..Print
16503// Print message to STR. If message is too short for MSG_LEN, print nothing.
16504// MSG.LENGTH must have already been validated against msg_len.
16505// This function will additionally validate that sizeof(Msg) <= msg_len
16506bool atf_amc::MsgHdrLTMsgs_Print(algo::cstring &str, atf_amc::MsgHdrLT &msg, u32 msg_len) {
16507 switch(msg.type) {
16508 case 'A': {
16509 if (sizeof(atf_amc::MsgLTA) > msg_len) { return false; }
16510 MsgLTA_Print((atf_amc::MsgLTA&)(msg), str);
16511 return true;
16512 }
16513 case 'B': {
16514 if (sizeof(atf_amc::MsgLTB) > msg_len) { return false; }
16515 MsgLTB_Print((atf_amc::MsgLTB&)(msg), str);
16516 return true;
16517 }
16518 case 'O': {
16519 if (sizeof(atf_amc::MsgLTO) > msg_len) { return false; }
16520 MsgLTO_Print((atf_amc::MsgLTO&)(msg), str);
16521 return true;
16522 }
16523 case 'V': {
16524 if (sizeof(atf_amc::MsgLTV) > msg_len) { return false; }
16525 MsgLTV_Print((atf_amc::MsgLTV&)(msg), str);
16526 return true;
16527 }
16528 default:
16529
16530 return false;
16531 }
16532}
16533
16534// --- atf_amc.MsgHeaderMsgs..Print
16535// Print message to STR. If message is too short for MSG_LEN, print nothing.
16536// MSG.LENGTH must have already been validated against msg_len.
16537// This function will additionally validate that sizeof(Msg) <= msg_len
16538bool atf_amc::MsgHeaderMsgs_Print(algo::cstring &str, atf_amc::MsgHeader &msg, u32 msg_len) {
16539 switch(msg.type) {
16540 case 0x0905: {
16541 if (sizeof(atf_amc::Seqmsg) > msg_len) { return false; }
16542 Seqmsg_Print((atf_amc::Seqmsg&)(msg), str);
16543 return true;
16544 }
16545 case 0x0412: {
16546 if (sizeof(atf_amc::Text) > msg_len) { return false; }
16547 Text_Print((atf_amc::Text&)(msg), str);
16548 return true;
16549 }
16550 case 0x1000: {
16551 if (sizeof(atf_amc::VarlenMsg) > msg_len) { return false; }
16552 VarlenMsg_Print((atf_amc::VarlenMsg&)(msg), str);
16553 return true;
16554 }
16555 default:
16556
16557 return false;
16558 }
16559}
16560
16561// --- atf_amc.Msgs..ReadStrptr
16562// Parse ascii representation of message into binary, appending new data to BUF.
16563atf_amc::MsgsCase atf_amc::Msgs_ReadStrptr(algo::strptr str, algo::ByteAry &buf) {
16564 bool ok = false;
16565 tempstr msgtype_str;
16566 algo::StringIter iter(str);
16567 cstring_ReadCmdarg(msgtype_str, iter, false); // read first word
16568 atf_amc::MsgsCase msgtype;
16569 value_SetStrptrMaybe(msgtype, msgtype_str); // map string -> enum
16570 switch (value_GetEnum(msgtype)) { // what message is it?
16571 case atf_amc_MsgsCase_atf_amc_VarlenK: {
16572 int len = sizeof(atf_amc::VarlenK);
16573 atf_amc::VarlenK *ctype = new(ary_AllocN(buf, len).elems) atf_amc::VarlenK; // default values
16574 algo::ByteAry varlenbuf;
16575 algo::ByteAry *varlenbuf_save = algo_lib::_db.varlenbuf;
16576 algo_lib::_db.varlenbuf = &varlenbuf;
16577 ok = VarlenK_ReadStrptrMaybe(*ctype, str); // now read attributes
16578 len += ary_N(varlenbuf);
16579 ctype->length = u32(len);
16580 ary_Addary(buf, ary_Getary(varlenbuf));
16581 algo_lib::_db.varlenbuf = varlenbuf_save;
16582 } break; // atf_amc::VarlenK case
16583
16584 default: break;
16585 }
16586 return ok ? msgtype : atf_amc::MsgsCase();
16587}
16588
16589// --- atf_amc.Msgs..ReadStrptrMaybe
16590// Parse ascii representation of message into binary, appending new data to BUF.
16591bool atf_amc::Msgs_ReadStrptrMaybe(algo::strptr str, algo::ByteAry &buf) {
16592 atf_amc::MsgsCase msgtype = Msgs_ReadStrptr(str,buf);
16593 return !(msgtype == atf_amc::MsgsCase());
16594}
16595
16596// --- atf_amc.Ssimfiles..ReadStrptr
16597// Parse ascii representation of message into binary, appending new data to BUF.
16598atf_amc::SsimfilesCase atf_amc::Ssimfiles_ReadStrptr(algo::strptr str, algo::ByteAry &buf) {
16599 bool ok = false;
16600 tempstr msgtype_str;
16601 algo::StringIter iter(str);
16602 cstring_ReadCmdarg(msgtype_str, iter, false); // read first word
16603 atf_amc::SsimfilesCase msgtype;
16604 value_SetStrptrMaybe(msgtype, msgtype_str); // map string -> enum
16605 switch (value_GetEnum(msgtype)) { // what message is it?
16606 case atf_amc_SsimfilesCase_dmmeta_Ctype: {
16607 int len = sizeof(dmmeta::Ctype);
16608 dmmeta::Ctype *ctype = new(ary_AllocN(buf, len).elems) dmmeta::Ctype; // default values
16609 ok = Ctype_ReadStrptrMaybe(*ctype, str); // now read attributes
16610 } break; // dmmeta::Ctype case
16611
16612 default: break;
16613 }
16614 return ok ? msgtype : atf_amc::SsimfilesCase();
16615}
16616
16617// --- atf_amc.Ssimfiles..ReadStrptrMaybe
16618// Parse ascii representation of message into binary, appending new data to BUF.
16619bool atf_amc::Ssimfiles_ReadStrptrMaybe(algo::strptr str, algo::ByteAry &buf) {
16620 atf_amc::SsimfilesCase msgtype = Ssimfiles_ReadStrptr(str,buf);
16621 return !(msgtype == atf_amc::SsimfilesCase());
16622}
16623
16624// --- atf_amc.MsgHdrLTMsgs..ReadStrptr
16625// Parse ascii representation of message into binary, appending new data to BUF.
16626atf_amc::MsgHdrLTMsgsCase atf_amc::MsgHdrLTMsgs_ReadStrptr(algo::strptr str, algo::ByteAry &buf) {
16627 bool ok = false;
16628 tempstr msgtype_str;
16629 algo::StringIter iter(str);
16630 cstring_ReadCmdarg(msgtype_str, iter, false); // read first word
16631 atf_amc::MsgHdrLTMsgsCase msgtype;
16632 value_SetStrptrMaybe(msgtype, msgtype_str); // map string -> enum
16633 switch (value_GetEnum(msgtype)) { // what message is it?
16634 case atf_amc_MsgHdrLTMsgsCase_atf_amc_MsgLTA: {
16635 int len = sizeof(atf_amc::MsgLTA);
16636 atf_amc::MsgLTA *ctype = new(ary_AllocN(buf, len).elems) atf_amc::MsgLTA; // default values
16637 ok = MsgLTA_ReadStrptrMaybe(*ctype, str); // now read attributes
16638 } break; // atf_amc::MsgLTA case
16639
16640 case atf_amc_MsgHdrLTMsgsCase_atf_amc_MsgLTB: {
16641 int len = sizeof(atf_amc::MsgLTB);
16642 atf_amc::MsgLTB *ctype = new(ary_AllocN(buf, len).elems) atf_amc::MsgLTB; // default values
16643 ok = MsgLTB_ReadStrptrMaybe(*ctype, str); // now read attributes
16644 } break; // atf_amc::MsgLTB case
16645
16646 case atf_amc_MsgHdrLTMsgsCase_atf_amc_MsgLTO: {
16647 int len = sizeof(atf_amc::MsgLTO);
16648 atf_amc::MsgLTO *ctype = new(ary_AllocN(buf, len).elems) atf_amc::MsgLTO; // default values
16649 algo::ByteAry varlenbuf;
16650 algo::ByteAry *varlenbuf_save = algo_lib::_db.varlenbuf;
16651 algo_lib::_db.varlenbuf = &varlenbuf;
16652 ok = MsgLTO_ReadStrptrMaybe(*ctype, str); // now read attributes
16653 len += ary_N(varlenbuf);
16654 ctype->len = u8(len-2);
16655 ary_Addary(buf, ary_Getary(varlenbuf));
16656 algo_lib::_db.varlenbuf = varlenbuf_save;
16657 } break; // atf_amc::MsgLTO case
16658
16659 case atf_amc_MsgHdrLTMsgsCase_atf_amc_MsgLTV: {
16660 int len = sizeof(atf_amc::MsgLTV);
16661 atf_amc::MsgLTV *ctype = new(ary_AllocN(buf, len).elems) atf_amc::MsgLTV; // default values
16662 algo::ByteAry varlenbuf;
16663 algo::ByteAry *varlenbuf_save = algo_lib::_db.varlenbuf;
16664 algo_lib::_db.varlenbuf = &varlenbuf;
16665 ok = MsgLTV_ReadStrptrMaybe(*ctype, str); // now read attributes
16666 len += ary_N(varlenbuf);
16667 ctype->len = u8(len-2);
16668 ary_Addary(buf, ary_Getary(varlenbuf));
16669 algo_lib::_db.varlenbuf = varlenbuf_save;
16670 } break; // atf_amc::MsgLTV case
16671
16672 default: break;
16673 }
16674 return ok ? msgtype : atf_amc::MsgHdrLTMsgsCase();
16675}
16676
16677// --- atf_amc.MsgHdrLTMsgs..ReadStrptrMaybe
16678// Parse ascii representation of message into binary, appending new data to BUF.
16679bool atf_amc::MsgHdrLTMsgs_ReadStrptrMaybe(algo::strptr str, algo::ByteAry &buf) {
16680 atf_amc::MsgHdrLTMsgsCase msgtype = MsgHdrLTMsgs_ReadStrptr(str,buf);
16681 return !(msgtype == atf_amc::MsgHdrLTMsgsCase());
16682}
16683
16684// --- atf_amc.MsgHeaderMsgs..ReadStrptr
16685// Parse ascii representation of message into binary, appending new data to BUF.
16686atf_amc::MsgType atf_amc::MsgHeaderMsgs_ReadStrptr(algo::strptr str, algo::ByteAry &buf) {
16687 bool ok = false;
16688 tempstr msgtype_str;
16689 algo::StringIter iter(str);
16690 cstring_ReadCmdarg(msgtype_str, iter, false); // read first word
16691 atf_amc::MsgType msgtype;
16692 value_SetStrptrMaybe(msgtype, msgtype_str); // map string -> enum
16693 switch (value_GetEnum(msgtype)) { // what message is it?
16694 case atf_amc_MsgType_atf_amc_Seqmsg: {
16695 int len = sizeof(atf_amc::Seqmsg);
16696 atf_amc::Seqmsg *ctype = new(ary_AllocN(buf, len).elems) atf_amc::Seqmsg; // default values
16697 algo::ByteAry varlenbuf;
16698 algo::ByteAry *varlenbuf_save = algo_lib::_db.varlenbuf;
16699 algo_lib::_db.varlenbuf = &varlenbuf;
16700 ok = Seqmsg_ReadStrptrMaybe(*ctype, str); // now read attributes
16701 len += ary_N(varlenbuf);
16702 ctype->length = atf_amc::MsgLength(len);
16703 ary_Addary(buf, ary_Getary(varlenbuf));
16704 algo_lib::_db.varlenbuf = varlenbuf_save;
16705 } break; // atf_amc::Seqmsg case
16706
16707 case atf_amc_MsgType_atf_amc_Text: {
16708 int len = sizeof(atf_amc::Text);
16709 atf_amc::Text *ctype = new(ary_AllocN(buf, len).elems) atf_amc::Text; // default values
16710 algo::ByteAry varlenbuf;
16711 algo::ByteAry *varlenbuf_save = algo_lib::_db.varlenbuf;
16712 algo_lib::_db.varlenbuf = &varlenbuf;
16713 ok = Text_ReadStrptrMaybe(*ctype, str); // now read attributes
16714 len += ary_N(varlenbuf);
16715 ctype->length = atf_amc::MsgLength(len);
16716 ary_Addary(buf, ary_Getary(varlenbuf));
16717 algo_lib::_db.varlenbuf = varlenbuf_save;
16718 } break; // atf_amc::Text case
16719
16720 case atf_amc_MsgType_atf_amc_VarlenMsg: {
16721 int len = sizeof(atf_amc::VarlenMsg);
16722 atf_amc::VarlenMsg *ctype = new(ary_AllocN(buf, len).elems) atf_amc::VarlenMsg; // default values
16723 algo::ByteAry varlenbuf;
16724 algo::ByteAry *varlenbuf_save = algo_lib::_db.varlenbuf;
16725 algo_lib::_db.varlenbuf = &varlenbuf;
16726 ok = VarlenMsg_ReadStrptrMaybe(*ctype, str); // now read attributes
16727 len += ary_N(varlenbuf);
16728 ctype->length = atf_amc::MsgLength(len);
16729 ary_Addary(buf, ary_Getary(varlenbuf));
16730 algo_lib::_db.varlenbuf = varlenbuf_save;
16731 } break; // atf_amc::VarlenMsg case
16732
16733 default: break;
16734 }
16735 return ok ? msgtype : atf_amc::MsgType();
16736}
16737
16738// --- atf_amc.MsgHeaderMsgs..ReadStrptrMaybe
16739// Parse ascii representation of message into binary, appending new data to BUF.
16740bool atf_amc::MsgHeaderMsgs_ReadStrptrMaybe(algo::strptr str, algo::ByteAry &buf) {
16741 atf_amc::MsgType msgtype = MsgHeaderMsgs_ReadStrptr(str,buf);
16742 return !(msgtype == atf_amc::MsgType());
16743}
16744
16745// --- atf_amc...MsgLTO_FmtByteAry
16746// Construct a new atf_amc::MsgLTO in the space provided by BUF.
16747// If BUF doesn't have enough space available, throw exception.
16748atf_amc::MsgLTO * atf_amc::MsgLTO_FmtByteAry(algo::ByteAry &buf, atf_amc::MsgHdrLT* o) {
16749 atf_amc::MsgLTO *msg = NULL;
16750 size_t len = sizeof(atf_amc::MsgLTO);
16751 int opt_len = o ? i32(o[0].len + 2) : 0;
16752 len += opt_len;
16753 ary_RemoveAll(buf);
16754 msg = (atf_amc::MsgLTO*)ary_AllocN(buf,len).elems;
16755 msg->len = u8(len + (-2));
16756 msg->type = char('O');
16757 if (o) {
16758 memcpy((u8*)msg + sizeof(atf_amc::MsgLTO), o, opt_len);
16759 }
16760 return msg;
16761}
16762
16763// --- atf_amc...MsgLTV_FmtByteAry
16764// Construct a new atf_amc::MsgLTV in the space provided by BUF.
16765// If BUF doesn't have enough space available, throw exception.
16766atf_amc::MsgLTV * atf_amc::MsgLTV_FmtByteAry(algo::ByteAry &buf, algo::memptr v) {
16767 atf_amc::MsgLTV *msg = NULL;
16768 size_t len = sizeof(atf_amc::MsgLTV);
16769 u32 ary_len = elems_N(v) * sizeof(u8);
16770 len += ary_len;
16771 ary_RemoveAll(buf);
16772 msg = (atf_amc::MsgLTV*)ary_AllocN(buf,len).elems;
16773 msg->len = u8(len + (-2));
16774 msg->type = char('V');
16775 memcpy(v_Addr(*msg), v.elems, ary_len);
16776 return msg;
16777}
16778
16779// --- atf_amc...OptG_FmtByteAry
16780// Construct a new atf_amc::OptG in the space provided by BUF.
16781// If BUF doesn't have enough space available, throw exception.
16782atf_amc::OptG * atf_amc::OptG_FmtByteAry(algo::ByteAry &buf, atf_amc::TypeG* typeg, int opt_len) {
16783 atf_amc::OptG *msg = NULL;
16784 size_t len = sizeof(atf_amc::OptG);
16785 len += opt_len;
16786 ary_RemoveAll(buf);
16787 msg = (atf_amc::OptG*)ary_AllocN(buf,len).elems;
16788 msg->length = u32(len + (0));
16789 if (typeg) {
16790 memcpy((u8*)msg + sizeof(atf_amc::OptG), typeg, opt_len);
16791 }
16792 return msg;
16793}
16794
16795// --- atf_amc...OptG_FmtMemptr
16796// Construct a new atf_amc::OptG in the space provided by BUF.
16797// If BUF doesn't have enough space available, throw exception.
16798// After constructing, advance BUF appropriate number of bytes forward
16799atf_amc::OptG * atf_amc::OptG_FmtMemptr(algo::memptr &buf, atf_amc::TypeG* typeg, int opt_len) {
16800 atf_amc::OptG *msg = NULL;
16801 size_t len = sizeof(atf_amc::OptG);
16802 len += opt_len;
16803 if (len > u32(elems_N(buf))) {
16804 return NULL; // no room.
16805 }
16806 msg = (atf_amc::OptG*)buf.elems;
16807 buf = RestFrom(buf,len);
16808 msg->length = u32(len + (0));
16809 if (typeg) {
16810 memcpy((u8*)msg + sizeof(atf_amc::OptG), typeg, opt_len);
16811 }
16812 return msg;
16813}
16814
16815// --- atf_amc...OptOptG_FmtByteAry
16816// Construct a new atf_amc::OptOptG in the space provided by BUF.
16817// If BUF doesn't have enough space available, throw exception.
16818atf_amc::OptOptG * atf_amc::OptOptG_FmtByteAry(algo::ByteAry &buf, atf_amc::OptG* optg) {
16819 atf_amc::OptOptG *msg = NULL;
16820 size_t len = sizeof(atf_amc::OptOptG);
16821 int opt_len = optg ? i32(optg[0].length) : 0;
16822 len += opt_len;
16823 ary_RemoveAll(buf);
16824 msg = (atf_amc::OptOptG*)ary_AllocN(buf,len).elems;
16825 msg->length = u32(len + (0));
16826 if (optg) {
16827 memcpy((u8*)msg + sizeof(atf_amc::OptOptG), optg, opt_len);
16828 }
16829 return msg;
16830}
16831
16832// --- atf_amc...OptOptG_FmtMemptr
16833// Construct a new atf_amc::OptOptG in the space provided by BUF.
16834// If BUF doesn't have enough space available, throw exception.
16835// After constructing, advance BUF appropriate number of bytes forward
16836atf_amc::OptOptG * atf_amc::OptOptG_FmtMemptr(algo::memptr &buf, atf_amc::OptG* optg) {
16837 atf_amc::OptOptG *msg = NULL;
16838 size_t len = sizeof(atf_amc::OptOptG);
16839 int opt_len = optg ? i32(optg[0].length) : 0;
16840 len += opt_len;
16841 if (len > u32(elems_N(buf))) {
16842 return NULL; // no room.
16843 }
16844 msg = (atf_amc::OptOptG*)buf.elems;
16845 buf = RestFrom(buf,len);
16846 msg->length = u32(len + (0));
16847 if (optg) {
16848 memcpy((u8*)msg + sizeof(atf_amc::OptOptG), optg, opt_len);
16849 }
16850 return msg;
16851}
16852
16853// --- atf_amc...Text_FmtByteAry
16854// Construct a new atf_amc::Text in the space provided by BUF.
16855// If BUF doesn't have enough space available, throw exception.
16856atf_amc::Text * atf_amc::Text_FmtByteAry(algo::ByteAry &buf, algo::aryptr<char > text) {
16857 atf_amc::Text *msg = NULL;
16858 size_t len = sizeof(atf_amc::Text);
16859 u32 ary_len = elems_N(text) * sizeof(char);
16860 len += ary_len;
16861 ary_RemoveAll(buf);
16862 msg = (atf_amc::Text*)ary_AllocN(buf,len).elems;
16863 msg->type = atf_amc::MsgType(0x0412);
16864 msg->length = atf_amc::MsgLength(len + (0));
16865 memcpy(text_Addr(*msg), text.elems, ary_len);
16866 return msg;
16867}
16868
16869// --- atf_amc...VarlenK_FmtByteAry
16870// Construct a new atf_amc::VarlenK in the space provided by BUF.
16871// If BUF doesn't have enough space available, throw exception.
16872atf_amc::VarlenK * atf_amc::VarlenK_FmtByteAry(algo::ByteAry &buf, algo::aryptr<u32 > i) {
16873 atf_amc::VarlenK *msg = NULL;
16874 size_t len = sizeof(atf_amc::VarlenK);
16875 u32 ary_len = elems_N(i) * sizeof(u32);
16876 len += ary_len;
16877 ary_RemoveAll(buf);
16878 msg = (atf_amc::VarlenK*)ary_AllocN(buf,len).elems;
16879 msg->length = u32(len + (0));
16880 memcpy(i_Addr(*msg), i.elems, ary_len);
16881 return msg;
16882}
16883
16884// --- atf_amc...VarlenK_FmtMemptr
16885// Construct a new atf_amc::VarlenK in the space provided by BUF.
16886// If BUF doesn't have enough space available, throw exception.
16887// After constructing, advance BUF appropriate number of bytes forward
16888atf_amc::VarlenK * atf_amc::VarlenK_FmtMemptr(algo::memptr &buf, algo::aryptr<u32 > i) {
16889 atf_amc::VarlenK *msg = NULL;
16890 size_t len = sizeof(atf_amc::VarlenK);
16891 u32 ary_len = elems_N(i) * sizeof(u32);
16892 len += ary_len;
16893 if (len > u32(elems_N(buf))) {
16894 return NULL; // no room.
16895 }
16896 msg = (atf_amc::VarlenK*)buf.elems;
16897 buf = RestFrom(buf,len);
16898 msg->length = u32(len + (0));
16899 memcpy(i_Addr(*msg), i.elems, ary_len);
16900 return msg;
16901}
16902
16903// --- atf_amc...main
16904int main(int argc, char **argv) {
16905 try {
16906 lib_json::FDb_Init();
16907 algo_lib::FDb_Init();
16908 lib_exec::FDb_Init();
16909 atf_amc::FDb_Init();
16910 algo_lib::_db.argc = argc;
16911 algo_lib::_db.argv = argv;
16912 algo_lib::IohookInit();
16913 atf_amc::ReadArgv(); // dmmeta.main:atf_amc
16914 atf_amc::Main(); // user-defined main
16915 } catch(algo_lib::ErrorX &x) {
16916 prerr("atf_amc.error " << x); // there may be additional hints in DetachBadTags
16917 algo_lib::_db.exit_code = 1;
16918 }
16919 if (algo_lib::_db.last_signal) {
16920 algo_lib::_db.exit_code = 1;
16921 }
16922 try {
16923 atf_amc::FDb_Uninit();
16924 lib_exec::FDb_Uninit();
16925 algo_lib::FDb_Uninit();
16926 lib_json::FDb_Uninit();
16927 } catch(algo_lib::ErrorX &) {
16928 // don't print anything, might crash
16929 algo_lib::_db.exit_code = 1;
16930 }
16931 // only the lower 1 byte makes it to the outside world
16932 (void)i32_UpdateMin(algo_lib::_db.exit_code,255);
16933 return algo_lib::_db.exit_code;
16934}
16935
16936// --- atf_amc...WinMain
16937#if defined(WIN32)
16938int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int) {
16939 return main(__argc,__argv);
16940}
16941#endif